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

调用方法:

    Intent intent=new Intent("youActionName");      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);       intent.addCategory(Intent.CATEGORY_DEFAULT);      intent.putExtra("type",inType);  //if needed       ComponentName cn=new ComponentName("applicationPackageName","packagename+classname");      intent.setComponent(cn);      startActivity(intent);  


在被调用的App里面需要定义 class (activity 或 service)属性和filter。需要明确的几点

如果不是action.Main,则需要主动申明Android:exported="true",允许外部访问

action name 要一致

category name要一致,如果调用的地方没有明确声明,被调用的地方要声明DEFAULT

<activity android:name=".pbap.BluetoothPbapLuancherActivity"               android:label="Bluetooth"              android:exported="true"              android:process="@string/process">      <intent-filter>                                         <action android:name="android.intent.action.MAIN" />          <category android:name="android.intent.category.DEFAULT" />       </intent-filter>  </activity>  


更多相关文章

  1. Android(安卓)解决方法数 65536 (65k) 限制
  2. android thread Interrupte使用方法
  3. android window.requestWindowFeature()常用方法(转)
  4. Android(安卓)Studio 用 JNI 实现与原生代码通信
  5. the bind value at index 2 is null
  6. android asset中 zip包解压sdcard
  7. android中webviewjs与java的相互调用
  8. Android隐藏标题栏的四种方法
  9. Android(安卓)menu使用

随机推荐

  1. Android系统源码目录解析
  2. Android软键盘处理开发规范
  3. 第一个Android程序
  4. 开机提示“Android正在升级...”
  5. Android伸手党系列之八:Android常用开发问
  6. android 的ViewPager的预加载机制及解决
  7. Android实践之简易天气(二)
  8. Android Weak Handler:可以避免内存泄漏的
  9. android 中的广播 ,系统广播和自定义广播
  10. [工作积累] android 中添加libssl和libcu