In order to realize the monitoring of multiple devices login in the project, an account needs to pop up a dialog box on the device when logging in to another device, so the global dialog box is used.
Plan 1.
1. Sometimes global pop-up dialog boxes are used in development, but permissions must be applied in manifest:
<uses-permission android:name=".SYSTEM_ALERT_WINDOW" />
2. Create Dialog
builder=new (this); (.logo_mini); ("Downline notification").setMessage("This account is logged in on another Android device.") .setPositiveButton("Re-Login", new () { @Override public void onClick(DialogInterface dialog, int which) { //do somthing } }).setNegativeButton("quit",new () { @Override public void onClick(DialogInterface dialog, int which) { Intent i=new Intent(,); (Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); } }); alertDialog = (); (false); (false); ().setType(.TYPE_SYSTEM_ALERT); ();
Note that you want to set the Window type of Dialog to .TYPE_SYSTEM_ALERT.
Plan II.
Problems caused by adoption plan one:
When installing the application, the user will ask the user whether to authorize it.
At the same time, on Xiaomi phones, the system pop-up box is prohibited by default. The system pop-up box in the application will not be able to pop-up
So can we not apply for system permissions and then pop up a prompt box to prompt the user?
Here we can change our thinking. Since the system pop-up box cannot pop up, we will not use the system pop-up box and give it an Activity substitution. But at this time, please note that when the Service is in or startActivity in ApplicationContext, you should add additional flags.tent.FLAG_ACTIVITY_NEW_TASK:
Intent i=new Intent(this,); (Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); //In the code, ActDialog is actually an Activity to apply the theme to it @android:style///Make the activity like a Dialog style
This solves the problem that permission application and the global Dialog cannot be displayed by default in Xiaomi mobile phones.
Finally, I would like to add that in Plan 1, you can pop up a dialog box without applying for permissions. Change the popup Window type to LayoutParams.TYPE_TOAST, but this type of popup box cannot accept event processing.
Implementing global dialog boxes using WindowManager
/** * Show pop-up box * * @param context */ public static void showPopupWindow(final Context context, final DialogCallback callback) { // Get WindowManager final WindowManager mWindowManager = (WindowManager) (Context.WINDOW_SERVICE); final params = new (); // type = .TYPE_SYSTEM_ALERT; // Set flag = .FLAG_ALT_FOCUSABLE_IM | .FLAG_NOT_FOCUSABLE; // If .FLAG_NOT_FOCUSABLE is set, the pop-up View cannot receive the Back key event // The transparent mask that does not set this pop-up box will be displayed as black = ; // FLAG_NOT_TOUCH_MODAL does not block the event to the subsequent window // Set FLAG_NOT_FOCUSABLE The floating window is small, and the application icon behind it changes from not being long-press to being long-pressible // If this flag is not set, there will be problems with the home page's screen stroke = .WRAP_CONTENT; = .WRAP_CONTENT; = ; TextView textView = new TextView(context); ("sfgsfdsfbsadfbasdfg"); (100); final View mView = (context).inflate(.item_dialog_exit, null); TextView tv_itemdialog_title = (TextView) (.tv_itemdialog_title); TextView tv_itemdialog_ok = (TextView) (.tv_itemdialog_ok); TextView tv_itemdialog_close = (TextView) (.tv_itemdialog_close); tv_itemdialog_ok.setText("Re-Login"); tv_itemdialog_close.setText("Login"); tv_itemdialog_title.setText("This account is logged in on other devices. If you are not operating, please modify your password in time to prevent information leakage."); tv_itemdialog_ok.setOnClickListener(new () { @Override public void onClick(View v) { // Hide pop-up window (mView); (); } }); tv_itemdialog_close.setOnClickListener(new () { @Override public void onClick(View v) { (mView); (); } }); (textView, params); }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.