Android(安卓)跨应用调用Activity及Service - 叶园 - 博客频道 - CSDN.NET
16lz
2021-01-24
如何调用另外一个app应用的activity或者service,本文提供一个验证可行的方法。
调用方法:
[java] view plain copy- Intentintent=newIntent("youActionName");
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.addCategory(Intent.CATEGORY_DEFAULT);
- intent.putExtra("type",inType);//ifneeded
- ComponentNamecn=newComponentName("applicationPackageName","packagename+classname");
- intent.setComponent(cn);
- startActivity(intent);
在被调用的App里面需要定义 class (activity 或 service)属性和filter。需要明确的几点
如果不是action.Main,则需要主动申明Android:exported="true",允许外部访问
action name 要一致
category name要一致,如果调用的地方没有明确声明,被调用的地方要声明DEFAULT
[html] view plain copy- <activityandroid:name=".pbap.BluetoothPbapLuancherActivity"
- android:label="Bluetooth"
- android:exported="true"
- android:process="@string/process">
- <intent-filter>
- <actionandroid:name="android.intent.action.MAIN"/>
- <categoryandroid:name="android.intent.category.DEFAULT"/>
- </intent-filter>
- </activity>
阅读全文……
更多相关文章
- 解决ScrollView与ListView的冲突的方法
- android intent.setDate方法
- Android(安卓)开源框架
- repo 切换分支一种简单的方法
- Android实现点击事件的三种方法
- Android(安卓)重写ViewGroup 分析onMeasure()和onLayout()方法
- Android下图片处理的的一些方法
- Android(安卓)adapter中调用activity中的方法
- Android(安卓): java.lang.UnsatisfiedLinkError: dalvik.system