Permission Setting and Self Startup Setting Method of Android

  • 2021-09-24 23:48:52
  • OfStack

In the development project, there are two major troubles:

1. There are many permissions involved in the system (taking pictures, recording, positioning, dialing, etc.).

For this, many people will refuse these permissions, which is embarrassing. They don't know what to do with us. This is not easy to use, that is not easy to use, and what is even more abominable is that the system settings of different mobile phones are not the same, so it is not easy to tell them where to set them. Therefore, the solution is to add a permission setting button in app so that app can jump directly to its permission setting interface, which is much more convenient. The code snippet is as follows:


/**
  *  Jump to Permission Setting Interface 
  */
 private void getAppDetailSettingIntent(Context context){
  Intent intent = new Intent();
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  if(Build.VERSION.SDK_INT >= 9){
   intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
   intent.setData(Uri.fromParts("package", 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", getPackageName());
  }
  startActivity(intent);
 }

2. The requirements for real-time push messages are very high.

On this issue, for the rookie I really is a big head... There are many customer reaction app running in the background on the dead, the notice can not be received.

After I searched once, I got some results.

First of all, the most basic thing is to ensure that service is not easy to be killed: 1. Adjust the priority of service to the maximum; 2. Self-startup in onDestroy ().


<intent-filter android:priority="1000">

Second, set persistent to true in the AndroidManifest. xml file.

Finally, set app to allow self-startup. (That's it! I have a big head!)

Here, I think about setting permission 1. Click a button directly and jump to the self-starting management page. However, I have searched online for a long time and have not found Intent of this system 1.

Instead, the current Activity is captured by executing the instruction adb shell dumpsys activity top. app can then jump through the specified ComponentName.

For example: I use red rice note3

Page of self-starting management in Redmi note3 system settings:

com.miui.securitycenter/com.miui.permcenter.autostart.AutoStartManagementActivity

So you can set up the page jump through the following code snippet:


private void selfStartManagerSettingIntent(Context context){

  String system = EquipmentSystemUtils.getSystem();
  Intent intent = new Intent();
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  ComponentName componentName = new ComponentName("com.huawei.systemmanager","com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity");
  intent.setComponent(componentName);
  try{
   context.startActivity(intent);
  }catch (Exception e){// Throw an exception and open the settings page directly 
   intent=new Intent(Settings.ACTION_SETTINGS);
   context.startActivity(intent);
  }

 }

However, what are other systems? The company is too shabby to have other Android machines. . . Ask all the kind-hearted great gods to provide 1 time. . .

What we know so far:


/**
  *  Jump to self-startup page 
  *
  *  Huawei  com.huawei.systemmanager/com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity
  *  Millet  com.miui.securitycenter/com.miui.permcenter.autostart.AutoStartManagementActivity
  * vivo com.iqoo.secure/.ui.phoneoptimize.AddWhiteListActivity
  * oppo com.coloros.oppoguardelf/com.coloros.powermanager.fuelgaue.PowerUsageModelActivity
  *
  */

There are many common systems that are hens, and I don't know if there are other concise methods. . .


Related articles: