解决ServiceIntent must be explicit

本文旨在解决在Android 5.0上遇到的'Service Intent must be explicit'警告。从Android 5.0开始,出于安全考虑,官方推荐在启动Service时使用显式Intent,避免使用隐式Intent,因为隐式Intent可能导致安全隐患并且从API级别21开始,bindService()调用隐式Intent会抛出异常。
摘要由CSDN通过智能技术生成


1       目的

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

 

使用Service的时需要采用隐私启动的方式,从Android 5.0后,其中有个特性就是Service Intent  must beexplitict,service必须采用显示方式启动。

据官网https://developer.android.com/guide/components/intents-filters.html#Types介绍:

注意:为了确保应用的安全性,启动 Service 时,请始终使用显式 Intent,且不要为服务声明 Intent 过滤器。使用隐式 Intent 启动服务存在安全隐患,因为您无法确定哪些服务将响应 Intent,且用户无法看到哪些服务已启动。从 Android 5.0(API 级别 21)开始,如果使用隐式 Intent 调用 bindService(),系统会引发异常。

2       解决方法

//方法1:
final Intent intent = new Intent();
intent.setAction(SERVIC
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值