跨app调用举例
假设有2个应用:应用1:com.test.app1 应用2:com.test.app2;应用1中注册了一个com.test.app1.TestActivity,下面我们根据注册方式分别说明 应用2调用应用1中TestActivity的情况。1、此种注册方式为私有,没有办法调用
<activity android:name="com.test.app1.TestActivity" >
</activity>
2、打破了公私规则,使得私有的变为公有,我们可以这样调用
intent.setComponent(new ComponentName("com.test.app1","com.test.app1.TestActivity"));
<activity android:name="com.test.app1.TestActivity" android:exported="true">
</activity>
3、公有的,我们可以这样调用:
intent.setComponent(new ComponentName("com.test.app1","com.test.app1.TestActivity"));
<activity android:name="com.test.app1.TestActivity" >
<intent-filter >
<action android:name=""/>
</intent-filter>
</activity>
4、我们可以显示调用,如3方式,同时我们可以隐式调用:
intent.setAction("com.test.app1.action");
<activity android:name="com.test.app1.TestActivity" >
<intent-filter >
<action android:name="com.test.app1.action"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
5、公有的变私有,无法调用
<activity android:name="com.test.app1.TestActivity" android:exported="false" >
<intent-filter >
<action android:name="com.test.app1.action"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
6、对于如果配置 <data android:mimeType=""/> 等属性的调用规则,可以使用隐式调用,网上有很多,此处省略。