Pop-up dialog box in Android radio receiver

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.