android8-android10静态广播收到到

2021-03-03  本文已影响0人  牵手生活

android8开始发送给静态广播需要明确设置ComponentName 参数

android8开始为静态广播设置ComponentName
/**
         * 其中ComponentName(参数1,参数2)
         * 参数1指的是你的app的包名,参数2指的是你的自定义广播所在的路径

         *
         */
        Intent intent = new Intent();
        intent.setAction(MqReceiver.Mq_Message);
        //写法一
        ComponentName componentName = new ComponentName("com.btzh.baidulocation","com.btzh.baidulocation.receiver.MqReceiver");
        //写法二
        //ComponentName componentName = new ComponentName(this,"com.btzh.baidulocation.receiver.MqReceiver");
        intent.setComponent(componentName);
        sendBroadcast(intent);


参考文献

Android8.0,9.0,10.0收不到静态注册的BroadcastReceiver

android 8.0静态广播接收不到
自定义广播接收不到(静态注册广播接收器)

上一篇 下一篇

猜你喜欢

热点阅读