java.lang.IllegalArgumentException: Service Intent must be explicit解决方法
来源:互联网 发布:淘宝买家具很久不发货 编辑:程序博客网 时间:2024/06/04 18:48
报错信息如下:
09-30 21:33:44.932 4531-4531/com.example.raid.bindservice E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.raid.bindservice, PID: 4531 java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.example.raid.service.FIRST_SERVICE } at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1688) at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1717) at android.app.ContextImpl.startService(ContextImpl.java:1701) at android.content.ContextWrapper.startService(ContextWrapper.java:516) at com.example.raid.bindservice.MainActivity$1.onClick(MainActivity.java:29) at android.view.View.performClick(View.java:4780) at android.view.View$PerformClick.run(View.java:19866) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
报错原因:
因为版本的原因,有些时候我们使用Service的时需要采用隐私启动的方式,但是Android 5.0一出来后,其中有个特性就是Service Intent must be explitict,也就是说从Lollipop开始,service服务必须采用显示方式启动。
5.0前的版本只需要如下代码即可开启服务:
final Intent intent = new Intent();intent.setAction("com.example.raid.service.FIRST_SERVICE");但是现在需要加上一个setPackage方法:
final Intent intent = new Intent(); intent.setAction("com.example.raid.service.FIRST_SERVICE"); intent.setPackage(getPackageName());
0 0
- java.lang.IllegalArgumentException: Service Intent must be explicit解决方法
- java.lang.IllegalArgumentException: Service Intent must be explicit解决方法
- java.lang.IllegalArgumentException: Service Intent must be explicit: Intent {
- java.lang.IllegalArgumentException: Service Intent must be explicit
- java.lang.IllegalArgumentException: Service Intent must be explicit
- java.lang.IllegalArgumentException: Service Intent must be explicit异常说明
- Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit:
- java.lang.IllegalArgumentException: Service Intent must be explicit
- java.lang.IllegalArgumentException: Service Intent must be explicit 异常说明
- java.lang.IllegalArgumentException: Service Intent must be explicit 异常解决
- java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=xxx}
- java.lang.IllegalArgumentException:Service Intent must be explicit:Intent{act=org.opencv.engine.BIND
- Android报错:Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent
- 解决Android5.0及以上启动Service时,java.lang.IllegalArgumentException: Service Intent must be explicit
- android L java.lang.IllegalArgumentException: Service Intent must be explicit隐式意图找不到错误解决
- 5.0上java.lang.IllegalArgumentException: Service Intent must be explicit异常
- 20_ java.lang.IllegalArgumentException: Service Intent must be explicit异常说明
- Android5.0报错:java.lang.IllegalArgumentException: Service Intent must be explicit
- javascript快速入门
- Unity 3D 控制物体上下左右均匀移动脚本
- 十一第二题
- 回溯法Perfect Cubes
- Decision Tree and Regression Tree
- java.lang.IllegalArgumentException: Service Intent must be explicit解决方法
- mysql bin-log日志记录
- 再谈OpenCV
- SURF项目总结 - deepdream
- 传智播客 工作流课程笔记
- 人脸识别Haar分类器
- 目标关键词是什么意思?
- 程序设计基石与实践之C语言指针和数组基础
- java学习笔记之IO流