android8.0静态广播问题

  • 隐式广播权限被收窄,大多数隐式广播已经不能被静态注册的广播接收者接收到了。建议采用动态注册广播接收者
  • 如果非要使用静态注册广播则有以下几点需要注意:
  1. 从8.0开始需要新增setComponent(“xxx”,”xxx” ),第一个参数是app包名,第二个是广播接收者路径,例如:
Intent intent = new Intent();
//指定广播的名字
intent.setAction("com.example.android21_zhangkai_broadcastreceiver.zk");      intent.setComponent(newComponentName("com.yiqi.zhiyuan","com.yiqi.zhiyuan.common.jpush.PushMessageReceiver"));
intent.putExtra("content", msg);
sendBroadcast(intent)
  1. AndroidManifest文件中需要注册reciver,并指明action,例如:

    
        
    

  1. 如果广播接收者是内部类,则必须是静态内部类,否则会接收不到消息,并且在AndroidManifest中注册时name需要用$符连接,例如:

    
        
    

你可能感兴趣的:(android8.0静态广播问题)