解决跨应用程序启动services报without a permission not allowed for APK的问题

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的全路径");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值