《完美解决系列》Android5.0以上 Implicit intents with startService are not safe
在Android6.0上,使用了以下代码:
Intent intent = new Intent();
intent.setAction("xxx.server");
bindService(intent, mConn, Context.BIND_AUTO_CREATE);
提示了警告的异常:
Implicit intents with startService are not safe
查了一下源码,原来在5.0上就必须强制使用显示方式来启动Service。
private void validateServiceIntent(Intent service) {
if (service.getComponent() == null && service.getPackage() == null) {
if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP) {
IllegalArgumentException ex = new IllegalArgumentException(
"Service Intent must be explicit: " + service);
throw ex;
} else {
Log.w(TAG, "Implicit intents with startService are not safe: " + service
+ " " + Debug.getCallers(2, 3));
}
}
}
解决方法:
设置Action的同时,还需要设置启动或绑定此Service类的packageName。
我们在此处使用系统的getPackageName函数来获取包名即可。
Intent intent = new Intent();
intent.setAction("xxx.server");
intent.setPackage(context.getPackageName());
bindService(intent, mConn, Context.BIND_AUTO_CREATE);
《完美解决系列》Android5.0以上 Implicit intents with startService are not safe的更多相关文章
- 完美解决VC++6.0与Visio/office不兼容问题!!!
话说电脑上如果装有VC++6.0编程软件和Visio或office办公软件,那么经常编程的人就会遇到下面的问题:VC打不开文件和工程,总是提示读取内存错误,点“确定”后vc自动关闭,但vc却能新建文件 ...
- 如何解决Android 5.0中出现的警告:Service Intent must be explicit
有些时候我们使用Service的时需要采用隐私启动的方式,但是Android 5.0一出来后,其中有个特性就是Service Intent must be explitict,也就是说从Lollip ...
- 解决Android 5.0中出现的警告:Service Intent must be explicit
extends:http://www.eoeandroid.com/thread-568853-1-1.html 本帖最后由 469874851 于 2015-3-11 18:15 编辑 有些时候我们 ...
- 我的Android进阶之旅------>如何解决Android 5.0中出现的警告: Service Intent must be explicit:
我的Android进阶之旅-->如何解决Android 5.0中出现的警告: java.lang.IllegalArgumentException: Service Intent must be ...
- 我的Android进阶之旅------>怎样解决Android 5.0中出现的警告: Service Intent must be explicit:
我的Android进阶之旅-->怎样解决Android 5.0中出现的警告: java.lang.IllegalArgumentException: Service Intent must be ...
- 如何解决Android 5.0以上出现的警告:Service Intent must be expli
有些时候我们使用Service的时需要采用隐私启动的方式,但是Android 5.0一出来后,其中有个特性就是Service Intent must be explitict,也就是说从Lollip ...
- 解决Android5.0以下Dialog引起的内存泄漏
最近项目开发中,开发人员和测试人员均反应在android5.0以下手机上LeakCanary频繁监控到内存泄漏,如下图所示,但凡用到Dialog或DialogFragment地方均出现了内存泄漏. 如 ...
- WebView 5.0+闪烁以及白屏问题完美解决
Android webView 在5.0+上启动硬件加速,造成部分手机出现闪烁.白屏等现象 必须写下这篇博客,遇到的问题搞了很久,百度谷歌就是没有完整的答案,记录下来,方便博友们: 需求:一个简单的W ...
- 完美解决AutoCAD2012,AutoCAD2013本身电脑里有NET4.0或以上版本却装不上的问题
适用情况:电脑里本身有NET4.0或4.5版本,并且正确安装.或本身你就装有AutoCAD2013或AutoCAD2012要装AutoCAD2012或AutoCAD2013却装不上的情况 如图1所示. ...
随机推荐
- FZU Tic-Tac-Toe -.- FZU邀请赛 FZU 2283
Problem L Tic-Tac-Toe Accept: 94 Submit: 184Time Limit: 1000 mSec Memory Limit : 262144 KB Pr ...
- Python 单元测试框架系列:聊聊 Python 的单元测试框架(一):unittest
作者:HelloGitHub-Prodesire HelloGitHub 的<讲解开源项目>系列,项目地址:https://github.com/HelloGitHub-Team/Arti ...
- 使用Spring Boot和RxJava的构建响应式REST API
我不打算解释什么是响应式编程,也不解释为什么要使用它.我希望你已经在其他地方了解过,如果没有,你可以使用Google去搜索它.在本文中,我将告诉您如何使用专门针对Spring Boot和RxJava的 ...
- NetCore下的HTTP请求IHttpClientFactory
使用方式 IHttpClientFactory有四种模式: 基本用法 命名客户端 类型化客户端 生成的客户端 基本用法 在 Startup.ConfigureServices 方法中,通过在 ISer ...
- 为什么说 Java 程序员必须掌握 Spring Boot ?(转)
Spring Boot 2.0 的推出又激起了一阵学习 Spring Boot 热,那么, Spring Boot 诞生的背景是什么?Spring 企业又是基于什么样的考虑创建 Spring Boot ...
- .Net基础篇_学习笔记_第六天_类型转换和方法(函数)简介
类型转换:Convert.ToInt32(); int.Parse(); int.TryParse(); Convert.ToInt32(); 的本质就是在使用 int.Parse(); int. ...
- c语言运算优先级与结合方向的问题
c语言运算的结合方向一直困扰我,不过我终于get到了哈哈 先附上c语言运算优先级和结合方向图片 以上有c语言一共的15个优先级,从上往下递增 c语言的运算符号有很多,当我们打代码或者看代码的时候符号多 ...
- Single Number 普通解及最小空间解(理解异或)
原题目 Given a non-empty array of integers, every element appears twice except for one. Find that singl ...
- 01 (H5*) Vue第一天
目录 1:什么是Vue.js 2:MVC和MVVM. 3:为什么要学习前段框架 4:框架和库的区别 5:怎么使用Vue. 6:常见的Vue指令 7: 五大事件修饰符 8:在vue中使用class样式 ...
- 44 (OC)* 野指针、空指针
一: 空指针 : 没有存储任何内存地址的指针就称为空指针(NULL指针). 被赋值为nil的指针,在没有被具体初始化之前,为nil.nil.Nil.NULL.NSNULL的含义和区别 nil:OC中的 ...