进程间的调用我觉得可以总结为三种:一种是注册系统服务,一种是调用package包名,最后一种是应该也是类似注册系统服务的方式,具体不知道什么方式。
一、注册系统服务
AIDL和调用系统的相册、拍照的时候都需要启动一个intent,指定action,而在AIDL中,如果要是server能够被调用的话,就需要在manifest文件里面注册系统服务,所以我觉得调用系统的相册、拍照等功能的时候也是在系统注册了服务,就把 这两种归结为一种。
server注册系统服务:
<service android:name="com.example.remoteservice.MyRemeoteService">
<!-- 进程间的AIDL需要进行配置intent-filter -->
<intent-filter>
<action android:name="com.example.remoteservice.action" />
</intent-filter>
</service>
client调用服务:
Intent intent = new Intent("com.example.remoteservice.action");
......
......
. .....
bindService(intent, conn, Context.BIND_AUTO_CREATE);
注意:其中client调用的action:com.example.remoteservice.action,就是server注册的actioncom.example.remoteservice.action;
二、调用package包名:这种方法是网上查到的,写过来总结一下
调用端:
//启动别的进程的activity
ComponentName componetName = new ComponentName(
//这个是另外一个应用程序的包名
"com.woxingwoxiu.showvideo.activity",
//这个参数是要启动的Activity
"com.woxingwoxiu.showvideo.activity.MainMyInfoActivity");
try {
Intent intent = new Intent();
intent.setComponent(componetName);
startActivity(intent);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "可以在这里提示用户没有找到应用程序,或者是做其他的操作!", 0).show();
}
被调用端:
<activity
android:name="com.woxingwoxiu.showvideo.activity.MainMyInfoActivity"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar"
android:windowSoftInputMode="adjustUnspecified|stateHidden" >
//需要调用的activity需要添加的action
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
注意:需要在被调用的activity里面添加action:android.intent.action.MAIN,要不然会报java.lang.SecurityException: Permission Denial: starting Intent,的错误;这种方式的调用也可以进行数据交互,具体的交互跟activity之间的数据交互是一样的,用intent传输数据。
三、这种是我在播放器的时候用到的,具体还不知道到底底层是用什么方式做的,不过推测应该也是类似注册的方式做的。需要在manifest文件里面添加对应的东西。
代码:
<activity android:name=".activity.System" android:screenOrientation="landscape" android:configChanges="keyboard|screenSize|orientation">
<!-- 让其他应用可以调用我的播放器start-->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="rtsp" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="video/*" />
<data android:mimeType="application/sdp" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:mimeType="video/mp4" />
<data android:mimeType="video/3gp" />
<data android:mimeType="video/3gpp" />
<data android:mimeType="video/3gpp2" />
</intent-filter>
<!-- 让其他应用可以调用我的播放器-end-->
</activity>
挖下坑,以后懂了什么原理再来埋。