appA去启动appB的Sevices的情况:
(1)appB的Services需要配置:
<service
android:name=".MyService"
android:exported="true"
android:permission="app.my.custom.services.permission">
<intent-filter>
<action android:name="android.intent.action.START_CUSTOM_SERVICE"/>
</intent-filter>
</service>
name、exported、permission这三个属性是必不可少的 另外添加 intent-filter 里面的 action 是自定义的
(2).appB中Mainfest.xml的权限配置
<permission android:name="app.custom.permission"
android:protectionLevel="signature"/>
<uses-permission android:name="app.custom.permission"/>
3.appA中Mainfest.xml的权限配置
<uses-permission android:name="app.custom.permission"/>
启动service的代码:
Intent intent = new Intent();
intent.setAction("android.intent.action.START_CUSTOM_SERVICE");
intent.setComponent(new ComponentName("com.dh.custom.services","com.dh.custom.services.MyService"));
startService(intent);
以上 new ComponentName("AppB的包名","AppB中Service的全路径");