問題描述
我正在使用 BroadcastReceiver
構建一個 android 應用程序,并且我想在 onReceive
啟動時顯示一個對話框.我想在手機上顯示對話框(無論用戶身在何處,都向用戶顯示對話框,例如收到消息時的 whatsapp 對話框).
I'm building an android application with BroadcastReceiver
and I want to show a dialog when onReceive
starts.
I want to show the dialog on the phone (show the user a dialog no matter where he is, like the whatsapp dialog when you get a message).
我該怎么做?
謝謝!
推薦答案
如果你想在廣播接收器的 onReceive
內部顯示一個對話框,你可以在廣播接收器內部啟動一個透明的活動一個警告對話框,從不調用 setContentView()
.該活動將具有透明視圖,并且只會顯示警報對話框.來源: 顯示系統重啟后廣播接收器中的警報對話框
If you want to show a dialog from inside your onReceive
of the BroadcastReceiver, inside your broadcast receiver you may start a transparent activity with an alert dialog and NEVER called setContentView()
. The activity will have an transparent view and only the alert dialog will show.
Source: show an alert dialog in broadcast receiver after a system reboot
有很多類似的帖子都在談論這個話題.有關代碼示例和其他評論,請參閱以下問題:
There are many similar posts which talk about this topic. See below questions for code samples and other reviews on the same:
BroadcastReceiver 中的 AlertDialog??能做到嗎?
如何從 BroadcastReceiver 發出警報對話框上課?
如何顯示來自 Android 廣播接收器的對話框?
如何從 BroadcastReceiver 設置 Alertbox
希望這會有所幫助.
這篇關于BroadcastReceiver onReceive 打開對話框的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!