Android启动另一个App的Service

13 篇文章 0 订阅

最近从 AppA 启动 AppB 的一个 service ,报了这个错误Not allowed to start service Intent

解决方案:

1.AppB中Service的配置

  <service
      android:name=".MyService"    
      android:exported="true"
      android:permission="app.custom.permission">

      <intent-filter>
           <action android:name="android.intent.action.START_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_SERVICE");
intent.setComponent(new ComponentName("com.aa.securityassitant","com.aa.securityassitant.MyService"));
startService(intent);

以上 new ComponentName("AppB的包名","AppB中Service的全路径");

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值