今天遇到如标题问题,查阅资料:http://blog.android-develop.com/2014/10/android-l-api-21-javalangillegalargumen.html

 /***
* Android L (lollipop, API 21) introduced a new problem when trying to invoke implicit intent,
* "java.lang.IllegalArgumentException: Service Intent must be explicit"
*
* If you are using an implicit intent, and know only 1 target would answer this intent,
* This method will help you turn the implicit intent into the explicit form.
*
* Inspired from SO answer: http://stackoverflow.com/a/26318757/1446466
* @param context
* @param implicitIntent - The original implicit intent
* @return Explicit Intent created from the implicit original intent
*/
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;
}

一个转换方法,如下方法调用:

 private void startMyIntentService() {
Intent startServiceIntent = new Intent("com.soyoungboy.intentservice");
Bundle bundle = new Bundle();
bundle.putString("param", "oper1");
startServiceIntent.putExtras(bundle);
startService(createExplicitFromImplicitIntent(this,startServiceIntent));
}

就可以了

Service Intent must be explicit的解决方法的更多相关文章

  1. Android Service Intent must be explicit的解决方法

    今天在学习Android的Service组件的时候,在AndroidMainfest.xml中定义了 <service android:name=".BindService" ...

  2. 【转】Service Intent must be explicit的解决方法

    原文网址:http://blog.csdn.net/shenzhonglaoxu/article/details/42675287 今天在学习android的Service组件的时候,在Android ...

  3. 如何解决Android 5.0中出现的警告:Service Intent must be explicit

    有些时候我们使用Service的时需要采用隐私启动的方式,但是Android 5.0一出来后,其中有个特性就是Service Intent  must be explitict,也就是说从Lollip ...

  4. 解决Android 5.0中出现的警告:Service Intent must be explicit

    extends:http://www.eoeandroid.com/thread-568853-1-1.html 本帖最后由 469874851 于 2015-3-11 18:15 编辑 有些时候我们 ...

  5. 我的Android进阶之旅------>如何解决Android 5.0中出现的警告: Service Intent must be explicit:

    我的Android进阶之旅-->如何解决Android 5.0中出现的警告: java.lang.IllegalArgumentException: Service Intent must be ...

  6. 我的Android进阶之旅------&gt;怎样解决Android 5.0中出现的警告: Service Intent must be explicit:

    我的Android进阶之旅-->怎样解决Android 5.0中出现的警告: java.lang.IllegalArgumentException: Service Intent must be ...

  7. java.lang.IllegalArgumentException: Service Intent must be explicit 解决办法

    java.lang.IllegalArgumentException: Service Intent must be explicit 意思是服务必须得显式的调用 我之前是这样使用绑定Service的 ...

  8. [Android分享] 如何解决Android 5.0中出现的警告:Service Intent must be explicit

    Android 5.0程序运行报Service Intent must be explicit错误,原因是5.0的service必须显式调用 改成 Intent intent = new Intent ...

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

    Intent intent = new Intent(); intent.setAction("remote.MyRemoteService.Action"); 使用AIDL调用远 ...

随机推荐

  1. 织梦调用多个栏目typeid="1,2,3"不支持的解决方法

    织梦arclist调用副栏目不显示的解决办法: 打开/include/taglib/arclist.lib.php,代码约位于295-296行,查找以下两行代码: if($CrossID=='') $ ...

  2. JavaWeb-Servlet-Tomcat

    Servlet就是运行在服务器上的Java类.Servlet容器为javaweb应用提供运行时环境,负责管理Servlet和JSP的生命周期,以及管理它们的共享数据. Servlet容器软件——Tom ...

  3. Linux系列——安装双系统Ubuntu

    作为一个穷人,电脑破得不行却没钱换,怎么办呢,不如换个Ubuntu吧,没有Windows那么多后台应用,在我这台古董上稍微流畅一点. Linux有很多发行版,比较流行和适合入门的就是Ubuntu和De ...

  4. git 创建管理多用户

    <搬运> Windows下Git多账号配置,同一电脑多个ssh-key的管理 一台电脑上的git同时使用两个github账户 git之https或http方式设置记住用户名和密码的方法

  5. XSS(Cross Site Script)

    类型一:反射型XSS 简单地把用户输入的数据“反射”给浏览器.也就是说,黑客需要诱使用户“点击”一个恶意链接,才能攻击成功. 类型二:存储型XSS 把用户输入的数据“存储”在服务器端.这种XSS具有很 ...

  6. java web 3.1-web.xml文件配置

    <?xml version="1.0" encoding="UTF-8" ?> <web-app xmlns:xsi="http:/ ...

  7. Python之并发编程-concurrent

    方法介绍 #1 介绍 concurrent.futures模块提供了高度封装的异步调用接口 ThreadPoolExecutor:线程池,提供异步调用 ProcessPoolExecutor: 进程池 ...

  8. 华策光通信: LED可见光通信室内定位项目获最具投资价值奖

    3月21日上午,一场持续3个多小时的O2O领域的创业DemoShow在深圳科兴科学园会议中心激烈上演.来自华策光通信的基于LED可见光通信室内精准定位项目作为LED与室内定位领域的跨界融合项目经过精彩 ...

  9. 20lanmo162326 2017-2018-1 《程序设计与数据结构》第1周学习总结

    20162326 2017-2018-1 <程序设计与数据结构>第1周学习总结 教材学习内容总结 算法:在特定计算模型下,解决问题的指令序列 计算 = 信息处理 也就是用工具,遵规则,机械 ...

  10. Runtime 类的使用

    package com.System.Runtime; import java.io.IOException; /* RunTime 该类类主要代表了应用程序运行的环境. getRuntime() 返 ...