最近在回看第一行代码时,做书上有关广播的例子时,发现高版本的android系统,对于广播的接收变得越来越严格,
导致自己写的demo中收不到广播,看了官网上的一些介绍 附上链接 :
https://developer.android.google.cn/about/versions/oreo/features/background-broadcasts
具体的解决办法就是
Intent intent =new Intent( "com.example.wenhaibo.androidstudy_broadcast02.MY_BROADCAST" ); intent.setComponent( new ComponentName( "com.example.wenhaibo.androidstudy_broadcast02" , "com.example.wenhaibo.androidstudy_broadcast02.MyBroadCastReceiver") ); sendBroadcast( intent );在 sendBroadcast(intent)方法之前,用intent 对象调用一下 setComponent( new ComponentName(''参数一'',''参数二'')) 参数一是你的包名,参数二是你的接收器的路径。