Service Intent must be explicit: Intent 解决

java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.google.android.gms.analytics.service.START (has extras) }

在Activity中启动Service的时候报错: 服务意图必须是显性声明。 这是为了防止造成冲突(i.e. 有多个Service用同样的intent-filter的情况)

这是Android 5.0 (Lollipop) 之后的规定。 不能用包名的方式定义Service Intent, 而要用显性声明:   new Intent(context, xxxService.class);

详细介绍可以看stackoverflow上的介绍。

解决办法如下:

1、通过显示意图启动Service(直接用类名);

  1. Intent intent = new Intent(com.yulore.test.AppService.class);  
  2. context.startService(intent);  

2、如果想继续使用隐式意图的话,加上包名信息即可;

  1. Intent intent = new Intent();  
  2. intent.setAction("com.yulore.recognize.android");  
  3. intent.setPackage(context.getPackageName());    //兼容Android 5.0  
  4. context.startService(intent);  

参考:

http://blog.csdn.net/shenzhonglaoxu/article/details/42675287

https://my.oschina.net/u/269663/blog/396826

http://blog.csdn.net/redarmy_chen/article/details/47832615

http://blog.csdn.net/ouyang_peng/article/details/50727693

http://blog.csdn.net/top_code/article/details/45719919

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值