java.lang.IllegalArgumentException: Service Intent must be explicit: Intent
在Activity中启动Service的时候报错: 服务意图必须是显性声明。 这是为了防止造成冲突(i.e. 有多个Service用同样的intent-filter的情况)
这是Android 5.0 (Lollipop) 之后的规定。 不能用包名的方式定义Service Intent, 而要用显性声明:
new Intent(context, xxxService.class);
如果一定要用隐性声明,可以用下面的方法(Stackoverflow上的回答)
public static 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;
}
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 意思是服务必须得显式的调用 我之前是这样使用绑定Service的 ...
- java.lang.IllegalArgumentException: Service not registered
java.lang.IllegalArgumentException: Service not registered 首先检查一下,Service是否在AndroidManifest文件中注册.格式如 ...
- [Android]Caused by: java.lang.IllegalArgumentException: Service not registered.md
Caused by: java.lang.IllegalArgumentException: Service not registered: org.diql.aidldemo.MainActivit ...
- Android用Intent来启动Service报“java.lang.IllegalArgumentException: Service Intent must be explicit”错误的解决方法
今天没事来写个播放器,照搬书上的原句,其中一句 //用于启动和停止service的Intent final Intent it = new Intent("android.mu.action ...
- Servlet.service() for servlet [jsp] in context with path [/Healthy_manager] threw exception [Unable to compile class for JSP] with root cause java.lang.IllegalArgumentException: Page directive: inval
严重: Servlet.service() for servlet [jsp] in context with path [/Healthy_manager] threw exception [Una ...
- java.lang.IllegalArgumentException: Result Maps collection does not contain value for java.lang.Integer
今天做springmvc+mybatis+spring的项目的时候发现了一个异常.如下: org.apache.ibatis.builder.IncompleteElementException: C ...
- java.lang.IllegalArgumentException 不合法的参数异常
报错内容: IllegalArgumentException 不合法的参数异常 十二月 06, 2016 10:06:56 上午 org.apache.catalina.core.StandardWr ...
- Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for …
编译通过并且运行web成功后,访问的页面不需要连接数据库,不牵扯到反射调用实体类就不会报错, 报错内容如下: [WARNING] org.springframework.web.util.Nested ...
- java.lang.IllegalArgumentException
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.Persiste ...
随机推荐
- uva202:循环小数(循环节+抽屉原理)
题意: 给出两个数n,m,0<=n,m<=3000,输出n/m的循环小数表示以及循环节长度. 思路: 设立一个r[]数组记录循环小数,u[]记录每次的count,用于标记,小数计算可用 r ...
- DelphiXE7操作sqlite数据库
准备工作: 1.用SQLiteExpertPers建立一个sqlite数据库. 2.打开delphi xe7. 一.FireDAC法 设置库联接 1.放入FDConnection1控件 2.放入FDC ...
- ocp 1Z0-051 141-175题解析
141. View the Exhibitand examine the structure of CUSTOMERS and GRADES tables. You need to displayna ...
- (转)UML用例图总结
用例图主要用来描述“用户.需求.系统功能单元”之间的关系.它展示了一个外部用户能够观察到的系统功能模型图. [用途]:帮助开发团队以一种可视化的方式理解系统的功能需求. 用例图所包含的元素如下: 1. ...
- 转载C# 对象转Json序列化
转载原地址: http://www.cnblogs.com/plokmju/p/ObjectByJson.html JSON Json(JavaScript Object Notation) 是一种 ...
- POJ 3259 Wormholes(SPFA判负环)
题目链接:http://poj.org/problem?id=3259 题目大意是给你n个点,m条双向边,w条负权单向边.问你是否有负环(虫洞). 这个就是spfa判负环的模版题,中间的cnt数组就是 ...
- VMware搭建12.0搭建Mac OS10.11详细过程
1.软件准备 1.1VMware12.0 1.2VMware增强包 1.3Mac OS10.11 cdr(相当于dmg) 1.4securable.exe 2.软件破解 2.1VMware输入序列号破 ...
- Eclipse查找类路径快捷方式
直接ctrl+shift+t查找这个类,下面会显示类的路径,包括jar名
- EasyUI 下拉列表联动
//绑定部门.人员下拉菜单项 function BindDdl() { var $ddlbm = $("#ddlBm");//部门下拉列表 var $ddlry = $(" ...
- 在Windows7上搭建Cocos2d-x 3.2alpha0开发环境
在windows7上搭建COCOS2D-X开发环境并不难, 但是由于框架更新过快,很多用户都有困难.我希望你们认为这个教程有用. 建议:为了避免安全相关的问题,请以管理员权限执行所有的操作,当运行命令 ...