之前在android7.0以及之前的版本中,发广播是一件很容易的,一句代码搞定:隐式广播,sendBroadcast(new Intent("android.intent.action.test"));

问题来了,可是在8.1上这样是行不通的。在PhoneWindowManager.java

发按键广播,就是接受不到,抓了log,报错如下:

W/BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.test flg=0x10 (has extras) 

翻了相关资料后,明白了。Android O版本对后台进程做了限制广播的发送,对隐式广播也做了限制;必须要指定接受广播类的包名和类名:

Intent intent = new Intent("android.intent.action.test");intent.setComponent(new ComponentName("接受广播的类的包名","接受广播的类的包名+类名"));            mContext.sendBroadcast(intent);

 

更多相关文章

  1. AndroidStudio3.4+ 导入旧版本moudle出现各种问题,禁用androidx
  2. Android(安卓)NDK配、编译、调试
  3. 百度地图长按事件
  4. linux下编译MTK android的环境搭建
  5. Android(安卓)API Level 与SDK版本对照表
  6. Could not find com.android.tools.build:gradle:3.6.2.
  7. com.android.build.api.transform.TransformException
  8. qt for android opencv 笔记
  9. 错误 java.lang.NoSuchMethodError: No static method getFont

随机推荐

  1. Android 抗锯齿的设置
  2. Android 插件化框架replugin使用教程之本
  3. Android Studio 报错 ERROR: Could not d
  4. 谷歌升级Android翻译 支持即时语音翻译
  5. Android(安卓)GLSurfaceView
  6. android笔记一(Button)
  7. android 对话框显示工具类
  8. Android中Task任务栈的四种模式
  9. Android拦截Home键
  10. Android常用工具类