當(dāng)你要適配8.0及以后的設(shè)備時(shí),舊代碼無(wú)法收到廣播
Beginning with Android 8.0 (API level 26), the system imposes additional restrictions on manifest-declared receivers.
If your app targets Android 8.0 or higher, you cannot use the manifest to declare a receiver for most implicit broadcasts (broadcasts that don't target your app specifically). You can still use a context-registered receiver when the user is actively using your app.
譯文:
從Android8.0開(kāi)始(APILevel26),系統(tǒng)對(duì)清單聲明的接收者施加額外的限制。如果您的應(yīng)用程序以Android8.0或更高版本為目標(biāo),則不能使用清單來(lái)為大多數(shù)隱式廣播(不是針對(duì)應(yīng)用程序的廣播)聲明接收器。當(dāng)用戶正在積極使用應(yīng)用程序時(shí),您仍然可以使用上下文注冊(cè)接收器。
解決方案
1.在清單文件中給廣播指定具體的廣播處理類,通過(guò)name屬性設(shè)定

以上是內(nèi)部類廣播name屬性的寫(xiě)法,如果通過(guò)新建廣播類單獨(dú)一個(gè)類文件的方式則為:
包名.廣播名
2.設(shè)置要發(fā)送給哪個(gè)廣播類處理
