How to pop up a dialog box inside a service
First give a demand: need to listen to the service inside the receiving text message, if received a text message, pop up a dialog to prompt the user to open.
See: (POPs up directly on the main desktop)
The service pop-up prompt box:
Alertdialog.builder Alertdialog = new Alertdialog.builder (this); Alertdialog.setmessage ("Is there a new message, are you viewing?") "); Alertdialog.setpositivebutton (" No ", new Dialoginterface.onclicklistener () {public void OnClick (dialoginterface dialog, int which) {}}); Alertdialog.setnegativebutton ("Yes", new Dialoginterface.onclicklistener () {public void OnClick ( Dialoginterface dialog, int which) {}}); ad = Alertdialog.create (); Ad.getwindow (). SetType (WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); Ad.setcanceledontouchoutside (false);//Click outside the area will not let dialog disappear ad.show ();
Don't forget to add permissions on the manifest:
<uses-permission android:name= "Android.permission.SYSTEM_ALERT_WINDOW"/>
Service Inside Popup dialog box