Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check MIUI autostart permission programmatically?

I need to check programmatically if the auto start permission for my app in MIUI phone is on or off. Facebook and whatsapp have this permission already enabled by default , how can I do so?

like image 480
Ekta Aggarwal Avatar asked Sep 07 '16 09:09

Ekta Aggarwal


People also ask

How do you check auto start permission is enabled or disabled programmatically?

There's no way to find out whether the Auto-start option is enabled or not. You can manually check under Security permissions => Autostart => Enable Autostart .

How do I get Miui security app auto start permission programmatically?

You need to give permissions in the in build security application for xiaomi. 1. open the security app 2. go to permissions 3. go to auto start 4. enable the applications that you want to keep running in the background!

What is autostart permission in Miui?

The autostart permission allows apps to be started by receiving an implicit broadcast intent. This method consists of scheduling an implicit broadcast with AlarmManager, killing the app and checking if the broadcast caused it to respawn.

What is autostart permission in redmi?

If you turn-ON Auto-start for all apps, even the apps that you don't use much, open in Background even if you cleared them from Recent apps. This eventually fills up RAM. If your phone has 4GB or so RAM, you may not feel the difference.


2 Answers

For now it's not possible.

As it's completely depend on their operating system API's and customisation. Even developers have requested for this on XIOMI's official forums but there is no response from there side.

Till now even i am finding an answer to this question but nothing helped me.

For the time being it will be only possible for rooted phones. i.e. making customisation in their firmware by becoming super user. But this is not at all advisable as it may damage user's phone.

EDIT 1

You can redirect user to autostart permission's settings page for enabling your app using following code

String manufacturer = "xiaomi"; if (manufacturer.equalsIgnoreCase(android.os.Build.MANUFACTURER)) {     //this will open auto start screen where user can enable permission for your app     Intent intent1 = new Intent();     intent1.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));     startActivity(intent1); } 

EDIT 2 I have recently used Mi A1 from XIOMI which have stock android (not miui) so this phone does not have autostart permission settings from miui. So take care while navigating user to the settings in such devices because it will not work here.

like image 128
Nikhil Avatar answered Sep 23 '22 17:09

Nikhil


100% working for oppo, vivo, xiomi, letv huawei, and honor

just call this function

private void addAutoStartup() {      try {         Intent intent = new Intent();         String manufacturer = android.os.Build.MANUFACTURER;         if ("xiaomi".equalsIgnoreCase(manufacturer)) {             intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));         } else if ("oppo".equalsIgnoreCase(manufacturer)) {             intent.setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity"));         } else if ("vivo".equalsIgnoreCase(manufacturer)) {             intent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));         } else if ("Letv".equalsIgnoreCase(manufacturer)) {             intent.setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity"));         } else if ("Honor".equalsIgnoreCase(manufacturer)) {             intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));         }          List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);         if  (list.size() > 0) {             startActivity(intent);         }     } catch (Exception e) {         Log.e("exc" , String.valueOf(e));     } } 
like image 44
Shubham Avatar answered Sep 25 '22 17:09

Shubham