您的位置:首页 > 编程语言 > Java开发

java.lang.IllegalArgumentException: Service Intent must be explicit

2016-03-29 17:23 555 查看
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







Intent intent = new Intent(com.yulore.test.AppService.class);

context.startService(intent);

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

[java] view
plain copy







Intent intent = new Intent();

intent.setAction("com.yulore.recognize.android");

intent.setPackage(context.getPackageName()); //兼容Android 5.0

context.startService(intent);

查询自:http://blog.csdn.net/top_code/article/details/45719919
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: