Not much to say, go straight to the car ...
1 Public classMyreceiverextendsBroadcastreceiver {2 @Override3 Public voidOnReceive (Finalcontext Context, Intent Intent) {4Alertdialog.builder Builder =NewAlertdialog.builder (context);5Builder.settitle ("Hint");6Builder.setmessage ("OK to open the main interface?") "); 7Builder.setpositivebutton ("OK",NewDialoginterface.onclicklistener () {8 @Override9 Public voidOnClick (Dialoginterface Dialog,intwhich) {TenIntent intent1 =NewIntent (context, mainactivity.class); One A //To start the activity in the broadcast receiver, be sure to add the FLAG_ACTIVITY_NEW_TASK flag to intent - intent1.addflags (intent.flag_activity_new_task); - context.startactivity (intent1); the } - }); - -Alertdialog dialog =builder.create (); + - //you need to set the dialog box type to Type_system_alert, otherwise the dialog cannot pop up in the broadcast receiver . + Dialog.getwindow (). SetType (WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); A dialog.show (); at } -}
Note: Set the type of dialog box to Type_system_alert so that a system-level dialog box pops up, so you must declare Android.permission.SYSTEM_ALERT_WINDOW permissions. Finally, don't forget to register the broadcast receiver.
Pop-up dialog box in Android radio receiver