java.lang.IllegalArgumentException: Service Intent must be explicit

来源:互联网 发布:ubuntu 打开jupyter 编辑:程序博客网 时间:2024/06/07 06:54

Android 5.0 手机上出现了崩溃:

AndroidRuntime: java.lang.RuntimeException: Unable to start receiver com.yulore.recognize.android.receiver.PhoneStateReceiver: java.lang.IllegalArgumentException: Service Intent must be explicit

经查询,原因是Android 5.0对Service Intent的调用策略发生改变了,必须通过显示Intent来启动Service,详细介绍可以看stackoverflow上的介绍。


解决办法如下:

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

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. Intent intent = new Intent(com.yulore.test.AppService.class);  
  2. context.startService(intent);  


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

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  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/top_code/article/details/45719919
0 0
原创粉丝点击