Android 跨应用调用Activity
2016-03-22 11:42
369 查看
http://blog.csdn.net/ouyangliping/article/details/7972141
如何调用另外一个app应用的activity或者service,本文提供一个验证可行的方法。
调用方法:
[java] view
plain copy
<pre name="code" class="java"><pre name="code" class="java">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); </pre>
<pre></pre>
<pre></pre>
</pre>
在被调用的App里面需要定义 class (activity 或 service)属性和filter。需要明确的几点
如果不是action.Main,则需要主动申明android:exported="true",允许外部访问(调用非主Activity注意这个)
action name 要一致
category name要一致,如果调用的地方没有明确声明,被调用的地方要声明DEFAULT
[java] view
plain copy
<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>
如何调用另外一个app应用的activity或者service,本文提供一个验证可行的方法。
调用方法:
[java] view
plain copy
<pre name="code" class="java"><pre name="code" class="java">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); </pre>
<pre></pre>
<pre></pre>
</pre>
在被调用的App里面需要定义 class (activity 或 service)属性和filter。需要明确的几点
如果不是action.Main,则需要主动申明android:exported="true",允许外部访问(调用非主Activity注意这个)
action name 要一致
category name要一致,如果调用的地方没有明确声明,被调用的地方要声明DEFAULT
[java] view
plain copy
<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>
相关文章推荐
- Android如何进行进程间通信之——Binder
- 安卓 jni 开发 —— Android Studio 打包 so 的坑
- 《Kotlin for android developers》中文版翻译
- 如何保证Android与服务器的DES加密保持一致
- android 推送实现总结
- Android——camera摄像头
- android 导入外部数据库注意事项
- Gson解析嵌套
- ANDROID 获得地理位置
- Android listview下拉刷新,上拉加载(发现一个比较好用的,和大家分享下)
- Android 多线程多任务断点续传
- ADB无线调试
- Android AsyncTask和Handler对比
- 你应该知道的那些Android小经验
- TextView的text内容包含双引号的问题
- Android打包的相关工具和命令
- Android 进程常驻(1)----开篇
- android常用工具类
- Android开发多线程断点续传下载器
- android学习者优秀网址推荐