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