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

调用方法:

[java] view plain copy
  1. Intentintent=newIntent("youActionName");
  2. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  3. intent.addCategory(Intent.CATEGORY_DEFAULT);
  4. intent.putExtra("type",inType);//ifneeded
  5. ComponentNamecn=newComponentName("applicationPackageName","packagename+classname");
  6. intent.setComponent(cn);
  7. startActivity(intent);

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

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

action name 要一致

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

[html] view plain copy
  1. <activityandroid:name=".pbap.BluetoothPbapLuancherActivity"
  2. android:label="Bluetooth"
  3. android:exported="true"
  4. android:process="@string/process">
  5. <intent-filter>
  6. <actionandroid:name="android.intent.action.MAIN"/>
  7. <categoryandroid:name="android.intent.category.DEFAULT"/>
  8. </intent-filter>
  9. </activity>

阅读全文……

更多相关文章

  1. 解决ScrollView与ListView的冲突的方法
  2. android intent.setDate方法
  3. Android(安卓)开源框架
  4. repo 切换分支一种简单的方法
  5. Android实现点击事件的三种方法
  6. Android(安卓)重写ViewGroup 分析onMeasure()和onLayout()方法
  7. Android下图片处理的的一些方法
  8. Android(安卓)adapter中调用activity中的方法
  9. Android(安卓): java.lang.UnsatisfiedLinkError: dalvik.system

随机推荐

  1. android:m/mm/mmm
  2. Android AIDL实例
  3. Android硬件抽象层(HAL)深入剖析(一)
  4. Android Layout布局文件里的android:layo
  5. android Uri详解
  6. android中shape绘制背景图片
  7. 《Android Dev Guide》系列教程10:用户界
  8. Android的adb命令介绍
  9. 一个让你掌握Android所有控件的Demo
  10. 【Android】Android 手机忘记锁屏密码的