Method for android to guide users to open self startup authority
- 2021-09-24 23:47:26
- OfStack
Foreword:
Recently, in the process of doing the project, I encountered the following 1 demand. Although it seems that it is not difficult to achieve, I encountered various pits in the process of realization. Record 1, which is convenient to view in the future! ! !
Requirements:
When the user installs APP for the first time, click the Authorization button to jump to the authorized page (different mobile phones jump to different authorized pages). After the user successfully authorizes, click the Back button to directly enter the main page
Question:
1. How to adapt to different models
2. Authorization pages of different models display different pop-up windows (such as 3-star display floating window and millet display pop-up window)
3. The millet pop-up window can never be displayed
4. Click the Back button on the authorization page to jump directly to the main page
Question 1: Adapt to different models
This is a blog post for reference (forget the place, find it later and add it ~ ~)
public class MobileInfoUtils{
private SettingDialogPermision dialog_per;
// Get mobile phone type
private static String getMobileType() {
return Build.MANUFACTURER;
}
// Jump to Authorization Page
public void jumpStartInterface(Context context) {
Intent intent = new Intent();
try {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Log.e("HLQ_Struggle", "****************** The current mobile phone model is: " + getMobileType());
ComponentName componentName = null;
if (getMobileType().equals("Xiaomi")) { // Red rice Note4 Pass the test
componentName = new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity");
} else if (getMobileType().equals("Letv")) { // LeTV 2 Pass the test
intent.setAction("com.letv.android.permissionautoboot");
} else if (getMobileType().equals("samsung")) { // 3 Star Note5 Pass the test
//componentName = new ComponentName("com.samsung.android.sm_cn", "com.samsung.android.sm.ui.ram.AutoRunActivity");
//componentName = ComponentName.unflattenFromString("com.samsung.android.sm/.ui.ram.RamActivity");// Permission Denial not exported from uid 1000 Is not allowed to be called by other programs
componentName = ComponentName.unflattenFromString("com.samsung.android.sm/.app.dashboard.SmartManagerDashBoardActivity");
} else if (getMobileType().equals("HUAWEI")) { // Huawei passed the test
//componentName = new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity");// Screen lock cleaning
componentName = ComponentName.unflattenFromString("com.huawei.systemmanager/.startupmgr.ui.StartupNormalAppListActivity");// Jump self-startup management
//SettingOverlayView.show(context);
} else if (getMobileType().equals("vivo")) { // VIVO Pass the test
componentName = ComponentName.unflattenFromString("com.iqoo.secure/.safeguard.PurviewTabActivity");
} else if (getMobileType().equals("Meizu")) { // Evil Meizu
//componentName = ComponentName.unflattenFromString("com.meizu.safe/.permission.PermissionMainActivity");// Jump to mobile butler
componentName = ComponentName.unflattenFromString("com.meizu.safe/.permission.SmartBGActivity");// Jump to the background management page
} else if (getMobileType().equals("OPPO")) { // OPPO R8205 Pass the test
componentName = ComponentName.unflattenFromString("com.oppo.safe/.permission.startup.StartupAppListActivity");
} else if (getMobileType().equals("ulong")) { // 360 Mobile phone Not tested
componentName = new ComponentName("com.yulong.android.coolsafe", ".ui.activity.autorun.AutoRunListActivity");
} else {
// Guide the user to the System Settings page
if (Build.VERSION.SDK_INT >= 9) {
Log.e("HLQ_Struggle", "APPLICATION_DETAILS_SETTINGS");
intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
intent.setData(Uri.fromParts("package", context.getPackageName(), null));
} else if (Build.VERSION.SDK_INT <= 8) {
intent.setAction(Intent.ACTION_VIEW);
intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
intent.putExtra("com.android.settings.ApplicationPkgName", context.getPackageName());
}
}
intent.setComponent(componentName);
context.startActivity(intent);
if (getMobileType().equals("Xiaomi")) {
showtip();// Display pop-up window ( ** Pay special attention ** )
}
if (getMobileType().equals("samsung")){
new SettingOverlayView().show(context);// Display floating window
}
} catch (Exception e) {// Throw an exception and open the settings page directly
Log.e("HLQ_Struggle", e.getLocalizedMessage());
intent = new Intent(Settings.ACTION_SETTINGS);
context.startActivity(intent);
}
}
// Xiaomi mobile phone display pop-up window
private void showtip() {
try {
dialog_per=new SettingDialogPermision(context, R.style.CustomDialog4);
dialog_per.getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST);// Note that it is changed to toast type here
dialog_per.show();
Log.e("HLQ_Struggle"," Display pop-up window ");
} catch (Exception e) {
e.printStackTrace();
Log.e("HLQ_Struggle", " No pop-up window displayed "+e.getMessage());
}
}
}
Question 2: Authorization pages of different models display different pop-up windows
Has been solved in the above problems.
The ideas are as follows:
First judge the current model
② After judging the model, jump to different authorization pages through intent
③ Display floating window or pop-up window after startActivity ()
④ Xiaomi mobile phone writes the following sentence when displaying the pop-up window:
getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST)
Because "toast" is not used here, the pop-up window is not displayed on Authorization Page 1
Question 3: The millet pop-up window can never be displayed
Solve in Step 4 of Question 2
Question 4: How can you jump directly to the main page by clicking the Back button on the authorization page
Logical combing:
Activity A--Click to request authorization-- > Jump to the system authorization page-click the back key- > Require a jump to the main page (i.e. MainActivity, note not Activity A)
In the process of implementation, I can't get the Activity of this authorized page. How can I monitor the return button? ? ? (Black question mark face)
So, at this time, the importance of Activity life cycle is reflected.
On the authorization page, after clicking the return button, you will jump to the Activity A page again. At this time, you only need to write the following code in Activity A to solve it perfectly:
protected void onRestart() {
super.onRestart();
Intent intent = new Intent(SelfStartAcitity.this,MainActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
finish();
}
This time it embodies the foundation again! Basics! Basics! How important it is!