Preface:
Recently, I encountered the following requirement during the project process. Although it seems not difficult to achieve, I encountered various pitfalls during the implementation process. Please record it and make it easier to view it in the future! ! !
need:
The user installed the APP for the first time and clicked the authorization button to jump to the authorized page (different phones jumped to different authorization pages). After the user's authorization is successful, click the return button to directly enter the main page.
question:
1. How to adapt to different models
2. Different models of authorization pages display different pop-up windows (such as Samsung displays floating windows, Xiaomi displays pop-up windows)
3. Xiaomi pop-up windows cannot be displayed
4. Click the return button on the authorization page to jump directly to the main page
Question 1: Adapt to different models
This is a blog post to learn from (I forgot the place, and I found it later and added it~~)
public class MobileInfoUtils{ private SettingDialogPermision dialog_per; //Get phone type private static String getMobileType() { return ; } //Skip to the authorization page public void jumpStartInterface(Context context) { Intent intent = new Intent(); try { (Intent.FLAG_ACTIVITY_NEW_TASK); ("HLQ_Struggle", "********************* The current mobile phone model is:" + getMobileType()); ComponentName componentName = null; if (getMobileType().equals("Xiaomi")) { // Redmi Note4 test passed componentName = new ComponentName("", ""); } else if (getMobileType().equals("Letv")) { // LeTV 2 test passed (""); } else if (getMobileType().equals("samsung")) { // Samsung Note5 test passed //componentName = new ComponentName(".sm_cn", ""); //componentName = ("/.");// Permission Denial not exported from uid 1000, not allowed to be called by other programs componentName = ("/."); } else if (getMobileType().equals("HUAWEI")) { // Huawei test passed //componentName = new ComponentName("", "");//Lock screen cleaning componentName = ("/.");//Skip self-start management //(context); } else if (getMobileType().equals("vivo")) { // VIVO test passed componentName = ("/."); } else if (getMobileType().equals("Meizu")) { //The evil charlatan //componentName = ("/.");//Skip to the mobile phone manager componentName = ("/.");//Skip to the background management page } else if (getMobileType().equals("OPPO")) { // OPPO R8205 test passed componentName = ("/."); } else if (getMobileType().equals("ulong")) { // 360 mobile phone not tested componentName = new ComponentName("", "."); } else { // Boot the user to the system settings page if (.SDK_INT >= 9) { ("HLQ_Struggle", "APPLICATION_DETAILS_SETTINGS"); (".APPLICATION_DETAILS_SETTINGS"); (("package", (), null)); } else if (.SDK_INT <= 8) { (Intent.ACTION_VIEW); ("", ""); ("", ()); } } (componentName); (intent); if (getMobileType().equals("Xiaomi")) { showtip();//Show pop-up window (**Take special attention**) } if (getMobileType().equals("samsung")){ new SettingOverlayView().show(context);//Show the floating window } } catch (Exception e) {// If an exception is thrown, open the settings page directly ("HLQ_Struggle", ()); intent = new Intent(Settings.ACTION_SETTINGS); (intent); } } //Xiaomi mobile phone display pop-up window private void showtip() { try { dialog_per=new SettingDialogPermision(context, .CustomDialog4); dialog_per.getWindow().setType(.TYPE_TOAST);//Note that it is changed to toast type here dialog_per.show(); ("HLQ_Struggle","Show pop-up window"); } catch (Exception e) { (); ("HLQ_Struggle", "No pop-up window is displayed"+()); } } }
Question 2: Different models of authorization pages show different pop-up windows
It has been solved in the above problem.
The idea is as follows:
①First judge the current model
②After judging the model, jump to a different authorization page through intent
③Show floating window or pop-up window after startActivity()
④ When Xiaomi mobile phone displays pop-up windows, write the following sentence:
getWindow().setType(.TYPE_TOAST)
Because the type here does not use "toast", the pop-up window will not be displayed on the authorization page.
Question 3: Xiaomi pop-up windows cannot be displayed
Solve in step 4 of issue 2
Question 4: How to directly jump to the main page by clicking the return button on the authorization page
Logical review:
Activity A———Click to request authorization——>Skip to the system authorization page———Click the back key——>Skip to the main page (that is, MainActivity, note that it is not Activity A)
During the implementation process, I have been stuck in a stubborn manner. I can't get the activity of this authorization page. How can I monitor the return button? ? ? (Black Question Mark Face)
So, at this time, the importance of the Activity life cycle is reflected.
On the authorization page, after clicking the return key, it will jump to the Activity A page again. At this time, you only need to write the following code in Activity A to solve the problem perfectly:
protected void onRestart() { (); Intent intent = new Intent(,); startActivity(intent); overridePendingTransition(.abc_fade_in, .abc_fade_out); finish(); }
This time, the foundation is reflected again! Base! Base! How important it is!
The above method to guide users to enable self-start permissions is all the content I share with you. I hope you can give you a reference and I hope you can support me more.