android8-android10靜態廣播收到到 參考文獻

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靜態廣播接收不到
自定義廣播接收不到(靜態註冊廣播接收器)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章