首页 > 其他 > 详细

AIDL使用绑定启动远程Service出现Service Intent must be explicit: Intent

时间:2020-02-03 19:44:00      阅读:61      评论:0      收藏:0      [点我收藏+]

技术分享图片

Intent intent = new Intent();
intent.setAction("remote.MyRemoteService.Action");

使用AIDL调用远程Service通过隐式意图的方式,但是出现了

Service Intent must be explicit: Intent { act=remote.MyRemoteService.Action }

抛出了一个异常,说意图不明确?

Android5.0以后绑定启动Service考虑到安全愿意,不允许隐式意图的方式启动,也就是说要给出一个明确的组件Service。intent.setPackage(String packageName)或者intent.setComponent(ComponentName componentName)都可以显示设置组件处理意图。那么下面这两种方式都能够解决:

Intent intent = new Intent();
intent.setAction("remote.MyRemoteService.Action");//Service过滤器的内容
intent.setPackage("cy.review.servicetest");//待使用远程Service所属应用的包名
Intent intent = new Intent();
intent.setAction("remote.MyRemoteService.Action");//Service过滤器的内容
//第一个参数待使用远程Service所属应用的包名,第二个参数所启动的远程Service完整类名
ComponentName componentName = new ComponentName(
        "cy.review.servicetest",
        "remote.MyRemoteService");
intent.setComponent(componentName);

参考:

https://blog.csdn.net/l2show/article/details/47421961

https://www.jianshu.com/p/52565022594e

AIDL使用绑定启动远程Service出现Service Intent must be explicit: Intent

原文:https://www.cnblogs.com/chen-ying/p/12256736.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!