Android 跨应用调用Activity


http://blog.csdn.net/ouyangliping/article/details/7972141

如何调用另外一个app应用的activity或者service,本文提供一个验证可行的方法。


调用方法:

[java]  view plain  copy
  1. <pre name="code" class="java"><pre name="code" class="java">Intent intent=new Intent("youActionName");  
  2. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);   
  3. intent.addCategory(Intent.CATEGORY_DEFAULT);  
  4. intent.putExtra("type",inType);  //if needed  
  5. ComponentName cn=new ComponentName("applicationPackageName","packagename+classname");  
  6. intent.setComponent(cn);  
  7. startActivity(intent);  </pre>  
  8. <pre></pre>  
  9. <pre></pre>  
  10. </pre>  

在被调用的App里面需要定义 class (activity 或 service)属性和filter。需要明确的几点
  1. 如果不是action.Main,则需要主动申明android:exported="true",允许外部访问(调用非主Activity注意这个)
  2. action name 要一致
  3. category name要一致,如果调用的地方没有明确声明,被调用的地方要声明DEFAULT
[java]  view plain  copy
  1. <activity android:name=".pbap.BluetoothPbapLuancherActivity"   
  2.             android:label="Bluetooth"  
  3.             android:exported="true"  
  4.             android:process="@string/process">  
  5.     <intent-filter>                                 
  6.         <action android:name="android.intent.action.MAIN" />  
  7.         <category android:name="android.intent.category.DEFAULT" />   
  8.     </intent-filter>  
  9. </activity>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值