自定義廣播接收不到(靜態註冊廣播接收器)

2021-09-26 03:20:21 字數 708 閱讀 1229

問題:按照《第一行**》中寫的自定義廣播接收器,採用靜態註冊的方式,在android8.0以及更高的版本中無法收到廣播資訊。需要給intent新增component或者setpackage也行,就是需要更明確的指定處理這個intent的元件資訊。

自定義廣播接收器**:

public class mybroadcastreceiver extends broadcastreceiver 

}

manifest中註冊資訊:

傳送廣播**:

button button = findviewbyid(r.id.button);

button.setonclicklistener(new view.onclicklistener() 

});

從原始碼這人兩個方法的注釋來看,setpackage是:

setcomponent是:

explicitly set the component to handle the intent.  明確指定處理這個intent的元件。

beginning with android 8.0 (api level 26), the system imposes additional restrictions on manifest-declared receivers.

Android 靜態註冊廣播收不到

一 問題現象 在進行android開發的時候,有多種方式和第三方應用進行通訊,常見的有aidl service receiver content provider等,這不,最近為了省事使用了廣播和第三方應用進行通訊,但是發現乙個問題,對方偶發收不到廣播,開始懷疑對方是不是動態註冊了廣播,和對方的開發...

自定義廣播

publicclassmainbroadcastreceiverextendsactivity 29 30 31 接收 publicclasshellobroadrecieverextendsbroadcastreceiver 18 19if intent.getaction equals andr...

自定義廣播

自定義廣播就是我們自己來寫廣播傳送者,也自己來寫廣播接收者。效果圖 1 自己寫好廣播傳送者 設定廣播的id,廣播接收者監聽的時候需要監聽這個 intent.setaction com.fry.receiver 這是給廣播接收者帶資料,沒這個也行 intent.putextra key 這是廣播傳送者...