Service Intent must be explicit的两种解决方法
来源:互联网 发布:php 拼接变量名 编辑:程序博客网 时间:2024/06/05 05:49
crash的原因是5.0以上service不能使用隐式intent启动,但是使用AIDL进行进程间通信时并不能得到具体的类名,so, 问题还得解决。
方法一
最简单的是新建Intent的时候带入packagename,直接调用setPackage方法,把service所在的包名设置进intent。
Intent intent = new Intent(); intent.setAction("com.boomstack.aidl"); intent.setPackage("com.boomstack.testaidlserver"); bindService(intent, serviceConnection, BIND_AUTO_CREATE);
方法二
根据隐式intent寻找具体的component,是根据PackageManager的
queryIntentServices方法获取所有符合intent的service,然后根据获取到的信息构建Component实例。
代码来自网络:
public Intent createExplicitFromImplicitIntent(Context context, Intent implicitIntent) { // Retrieve all services that can match the given intent PackageManager pm = context.getPackageManager(); List<ResolveInfo> resolveInfo = pm.queryIntentServices(implicitIntent, 0); // Make sure only one match was found if (resolveInfo == null || resolveInfo.size() != 1) { return null; } // Get component info and create ComponentName ResolveInfo serviceInfo = resolveInfo.get(0); String packageName = serviceInfo.serviceInfo.packageName; String className = serviceInfo.serviceInfo.name; ComponentName component = new ComponentName(packageName, className); // Create a new intent. Use the old one for extras and such reuse Intent explicitIntent = new Intent(implicitIntent); // Set the component to be explicit explicitIntent.setComponent(component); return explicitIntent; }
原理是一样的,都是为了获取具体的组件信息,方法二比方法一更通用一些。
0 0
- Service Intent must be explicit的两种解决方法
- Service Intent must be explicit的解决方法
- Service Intent must be explicit的解决方法
- Service Intent must be explicit的解决方法
- Service Intent must be explicit的解决方法
- Service Intent must be explicit的解决方法
- Service Intent must be explicit的解决方法
- Service Intent must be explicit的解决方法:续
- 安卓Service Intent must be explicit的解决方法
- Service Intent must be explicit的解决方案
- Service Intent must be explicit
- Service Intent must be explicit
- Service Intent must be explicit
- java.lang.IllegalArgumentException: Service Intent must be explicit解决方法
- java.lang.IllegalArgumentException: Service Intent must be explicit解决方法
- Service Intent must be explicit 原因和解决方法
- 使用aidl隐式调用service出现service intent must be explicit 问题的一种解决方法
- 启动 Service 出现 Service Intent must be explicit 三种解决方法
- Maven仓库基础知识学习
- Deep Speech笔记
- TCP/IP:UDP(2) IP分片
- IDEA 常用插件
- 如何使用busybox编译和生成最简linux根文件系统(rootfs)
- Service Intent must be explicit的两种解决方法
- 2017.2.3初次接触codeforces
- thinkphp phpmailer发送邮件
- [Codeforces Round #394 DIV2C (CF761C)] Dasha and Password
- 2017,新的开始,加油
- poj 3026 Borg Maze(bfs+prim)
- 共同学习Java源代码-数据结构-HashMap(三)
- 模板设计模式
- 【杭电1006】计算时钟指针分别呈相同角度的时间长度(AC)