美文网首页
android8-android10静态广播收到到

android8-android10静态广播收到到

作者: 牵手生活 | 来源:发表于2021-03-03 16:09 被阅读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静态广播接收不到
自定义广播接收不到(静态注册广播接收器)

相关文章

网友评论

      本文标题:android8-android10静态广播收到到

      本文链接:https://www.haomeiwen.com/subject/linqqltx.html