31

Some Android devices due to custom Android tweaks are done by manufacturers has some politics about Power Management that breaks some features like push notifications.

  • Huawei - Only Pre-EMUI 5.0 / Android 7 - Go to Settings > "Protected apps", check your app.
  • Sony - Tap on the battery icon. Go to Power Management > STAMINA mode > Apps active in standby > Add your app.
  • Asus - Check your app in the Auto-start Manager.
  • Xiaomi - Security (App) > Permissions > Autostart - Enable your app
  • *New Xiaomi - Settings > Developer Options. Disable "memory optimization". To enabled Developer Options go to Settings > About. Tap on MIUI 8 times.
  • Oppo - Go to Settings > "Security settings" > "Data saving" and enable your app.
  • Samsung - Disable battery usage optimizations

I want to collect intents to launch respective tools, but I have found only for Huawei and Xiaomi.

Intent INTENT_HUAWEI = new Intent().setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
Intent INTENT_XIAOMI = new Intent().setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));

if (getPackageManager().resolveActivity(INTENT_HUAWEI, PackageManager.MATCH_DEFAULT_ONLY) != null)
    startActivity(INTENT_HUAWEI);
else if (getPackageManager().resolveActivity(INTENT_XIAOMI, PackageManager.MATCH_DEFAULT_ONLY) != null)
    startActivity(INTENT_XIAOMI);

I need help from all other producers, thz

Xan
  • 3,550
  • 4
  • 25
  • 36

3 Answers3

80

i have collected some intent from various post:

    private static final Intent[] POWERMANAGER_INTENTS = {
            new Intent().setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")),
            new Intent().setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity")),
            new Intent().setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity")),
            new Intent().setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity")),
            new Intent().setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity")),
            new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity")),
            new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.startupapp.StartupAppListActivity")),
            new Intent().setComponent(new ComponentName("com.oppo.safe", "com.oppo.safe.permission.startup.StartupAppListActivity")),
            new Intent().setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity")),
            new Intent().setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.BgStartUpManager")),
            new Intent().setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity")),
            new Intent().setComponent(new ComponentName("com.samsung.android.lool", "com.samsung.android.sm.battery.ui.BatteryActivity")),
            new Intent().setComponent(new ComponentName("com.samsung.android.lool", "com.samsung.android.sm.ui.battery.BatteryActivity")),
            new Intent().setComponent(new ComponentName("com.htc.pitroad", "com.htc.pitroad.landingpage.activity.LandingPageActivity")),
            new Intent().setComponent(new ComponentName("com.asus.mobilemanager", "com.asus.mobilemanager.MainActivity")),
            new Intent().setComponent(new ComponentName("com.transsion.phonemanager", "com.itel.autobootmanager.activity.AutoBootMgrActivity"))
    }; 

            for (Intent intent : POWERMANAGER_INTENTS)
                if (getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
                    // show dialog to ask user action
                    break;
                }

after user agree

for (Intent intent : POWERMANAGER_INTENTS)
  if (getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
  startActivity(intent);
  break;
}

seams new releases require this permissions

<uses-permission android:name="oppo.permission.OPPO_COMPONENT_SAFE"/>
<uses-permission android:name="com.huawei.permission.external_app_settings.USE_COMPONENT"/>

i want to collect all intent to open power manager, if anyone found mistake or want to improve something, comment here

Xan
  • 3,550
  • 4
  • 25
  • 36
  • 5
    Looks like we try to achieve the same thing. Can you please check this Github repo? https://github.com/dirkam/backgroundable-android – drk Feb 11 '18 at 11:38
  • yes, i have collected more intents, you have collected more details. on xiaomi we have found different intent – Xan Feb 13 '18 at 10:05
  • I believe Github is a better platform for this, would you mind contributing? Still, a lot of other OEMs to cover, maybe others can help, too. – drk Feb 14 '18 at 16:49
  • 1
    would you updated this? is it still up to date for Samsung? – kilian eller Apr 12 '18 at 15:08
  • @kilianeller more or less. if anyone post a comment, i will update answer – Xan Apr 12 '18 at 15:09
  • 7
    Huawei removed its "protected apps" in recent versions of EMUI, in favour of a new activity `com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity`. – hoshiKuzu Jul 16 '18 at 18:22
  • For HTC, there's Boost+: `com.htc.pitroad/.landingpage.activity.LandingPageActivity` - then select "manage background apps" (or similar). – Jule Jul 27 '18 at 09:54
  • @Jule i have no htc now, pls make and test an intent and i will add in main post. somethings like new Intent().setComponent(new ComponentName("com.htc.pitroad", "com.htc.pitroad.landingpage.activity.LandingPageActivity")) pls test – Xan Jul 27 '18 at 10:19
  • @Xan yes precisely that intent works, tested it. And I found out by now that the Boost+ app is also available in the play store, so not limited to HTC devices (although those come with it pre-installed). – Jule Jul 30 '18 at 08:34
  • @Jule added to main post – Xan Jul 30 '18 at 18:13
  • Hi all , Thanks for the list , But how we can find user make my app to stop running or mark the app under sleeping apps ? – Thom Aug 06 '18 at 07:39
  • simple you can't – Xan Aug 06 '18 at 08:03
  • 6
    The Huawei intent from my older comment no longer works on pie. It crashes with a SecurityException. – hoshiKuzu Apr 22 '19 at 16:25
  • i cant try now, if you find solution i will update post – Xan Apr 23 '19 at 13:39
  • 2
    What is the new huawei battery settings (App launch) intent in android 9 Pie? – Saeed Arianmanesh Apr 28 '19 at 07:10
  • 1
    I am getting crash with this log :::::::java.lang.SecurityException: Permission Denial: starting Intent { cmp=com.coloros.safecenter/.startupapp.StartupAppListActivity } from ProcessRecord{7bca5d9 20179:com.appname/u0a230} (pid=20179, uid=10230) requires oppo.permission.OPPO_COMPONENT_SAFE – himCream Apr 28 '19 at 07:33
  • so using "oppo.permission.OPPO_COMPONENT_SAFE" permission works ? – Xan Apr 29 '19 at 10:10
  • 1
    New Huawei P30 Pro (VOG-L29) using Android Pie displays error "permission USE_COMPONENT is required". So I think we have to add the line in manifest. – Ton May 01 '19 at 17:46
  • 4
    I added these permissions and code... but I think that on Huawei running Android 9, these permissions do not register. I still have a securityException. Anyone else encountered this? – Alon Minski Jun 23 '19 at 15:05
  • 16
    I must say that adding "com.huawei.permission.external_app_settings.USE_COMPONENT" permission does not work on my Huawei P20 (AN Pie) but I found out that I can use `ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity") `instead. – David Sucharda Jun 23 '19 at 15:41
  • @DavidSucharda added in list – Xan Jun 24 '19 at 09:49
  • @DavidSucharda this is so hard for users, i think... but no any other ways exist. Thank you. – AlexS Jul 04 '19 at 12:34
  • 3
    @AlexS It is, I completely agree. Problem is that Huawei for example kills every background activity after 12 seconds of device inactivity. Not even Foreground service is spared, which is crazy. Other thing is that sometimes it is "disable" optimization and sometimes "enable" manual optimization. So you can mislead the user with your wording in the application. – David Sucharda Jul 05 '19 at 16:29
  • @AlonMinski Did you resolve that security exception issue? – Sethuraman Srinivasan Jul 22 '19 at 01:56
  • @himCream Did you resolve that security exception issue? – Sethuraman Srinivasan Jul 22 '19 at 01:57
  • 3
    @SethuramanSrinivasan yes. I launched a different activity in Android 9: new Intent().setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity")) – Alon Minski Aug 05 '19 at 08:32
  • 2
    StartupNormalAppListActivity should be first unless it crashes (security exception). – itay83 Nov 04 '19 at 11:03
  • This Gist is a working example, but beware of SecurityExceptions as mentioned in the other comments: https://gist.github.com/moopat/e9735fa8b5cff69d003353a4feadcdbc – Chris Watts Apr 08 '20 at 11:43
  • Note at some point samsung changed the activity name from com.samsung.android.sm.ui.battery.BatteryActivity to com.samsung.android.sm.battery.ui.BatteryActivity . See my response to a related question here: https://stackoverflow.com/a/63632966/621465 – Elroid Aug 28 '20 at 11:39
  • 1
    For the latest Samsung devices use `com.samsung.android.sm.battery.ui.BatteryActivity` instead of `com.samsung.android.sm.ui.battery.BatteryActivity` – beginner Feb 24 '21 at 12:05
  • aggiornato il post – Xan Feb 24 '21 at 13:58
  • I've tested this on Oppo A1601 running Android 6.0, adding `oppo.permission.OPPO_COMPONENT_SAFE` still cause an exception when starting `com.coloros.safecenter.startupapp.StartupAppListActivity`, currently working alternative is adding it's parent activity `com.coloros.privacypermissionsentry.PermissionTopActivity` and let users click inside by themselves. This solution is referred from [https://stackoverflow.com/questions/49814755/denial-permission-oppo-component-safe](https://stackoverflow.com/questions/49814755/denial-permission-oppo-component-safe) – Lynch Chen Mar 03 '21 at 22:33
  • I've tested the above codes on some newer SAMSUNG, OnePlus phones running android 10+, seems like `com.samsung.android.sm.ui.battery.BatteryActivity` doesn't have a whitelist page for apps anymore, they're acting more like an AOSP. Opening the battery page of SAMSUNG doesn't help in this case, I can't find any place to whitelist my app. In this condition, I suggest separate PowerSaving and Autostart, for PowerSaving thing, first check existence&start `new Intent().setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)` , if not exist, then open vendor-specific battery activity. – Lynch Chen Mar 05 '21 at 01:16
9

Try this code-:

private void enableAutoStart() {
    if (Build.BRAND.equalsIgnoreCase("xiaomi")) {
      new MaterialDialog.Builder(MainActivity.this).title("Enable AutoStart")
        .content(
          "Please allow AppName to always run in the background,else our services can't be accessed.")
        .theme(Theme.LIGHT)
        .positiveText("ALLOW")
        .onPositive(new MaterialDialog.SingleButtonCallback() {
          @Override
          public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {

            Intent intent = new Intent();
            intent.setComponent(new ComponentName("com.miui.securitycenter",
              "com.miui.permcenter.autostart.AutoStartManagementActivity"));
            startActivity(intent);
          }
        })
        .show();
    } else if (Build.BRAND.equalsIgnoreCase("Letv")) {
      new MaterialDialog.Builder(MainActivity.this).title("Enable AutoStart")
        .content(
          "Please allow AppName to always run in the background,else our services can't be accessed.")
        .theme(Theme.LIGHT)
        .positiveText("ALLOW")
        .onPositive(new MaterialDialog.SingleButtonCallback() {
          @Override
          public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {

            Intent intent = new Intent();
            intent.setComponent(new ComponentName("com.letv.android.letvsafe",
              "com.letv.android.letvsafe.AutobootManageActivity"));
            startActivity(intent);
          }
        })
        .show();
    } else if (Build.BRAND.equalsIgnoreCase("Honor")) {
      new MaterialDialog.Builder(MainActivity.this).title("Enable AutoStart")
        .content(
          "Please allow AppName to always run in the background,else our services can't be accessed.")
        .theme(Theme.LIGHT)
        .positiveText("ALLOW")
        .onPositive(new MaterialDialog.SingleButtonCallback() {
          @Override
          public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName("com.huawei.systemmanager",
              "com.huawei.systemmanager.optimize.process.ProtectActivity"));
            startActivity(intent);
          }
        })
        .show();
    } else if (Build.MANUFACTURER.equalsIgnoreCase("oppo")) {
      new MaterialDialog.Builder(MainActivity.this).title("Enable AutoStart")
        .content(
          "Please allow AppName to always run in the background,else our services can't be accessed.")
        .theme(Theme.LIGHT)
        .positiveText("ALLOW")
        .onPositive(new MaterialDialog.SingleButtonCallback() {
          @Override
          public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            try {
              Intent intent = new Intent();
              intent.setClassName("com.coloros.safecenter",
                "com.coloros.safecenter.permission.startup.StartupAppListActivity");
              startActivity(intent);
            } catch (Exception e) {
              try {
                Intent intent = new Intent();
                intent.setClassName("com.oppo.safe",
                  "com.oppo.safe.permission.startup.StartupAppListActivity");
                startActivity(intent);
              } catch (Exception ex) {
                try {
                  Intent intent = new Intent();
                  intent.setClassName("com.coloros.safecenter",
                    "com.coloros.safecenter.startupapp.StartupAppListActivity");
                  startActivity(intent);
                } catch (Exception exx) {

                }
              }
            }
          }
        })
        .show();
    } else if (Build.MANUFACTURER.contains("vivo")) {
      new MaterialDialog.Builder(MainActivity.this).title("Enable AutoStart")
        .content(
          "Please allow AppName to always run in the background.Our app runs in background else our services can't be accesed.")
        .theme(Theme.LIGHT)
        .positiveText("ALLOW")
        .onPositive(new MaterialDialog.SingleButtonCallback() {
          @Override
          public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            try {
              Intent intent = new Intent();
              intent.setComponent(new ComponentName("com.iqoo.secure",
                "com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity"));
              startActivity(intent);
            } catch (Exception e) {
              try {
                Intent intent = new Intent();
                intent.setComponent(new ComponentName("com.vivo.permissionmanager",
                  "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
                startActivity(intent);
              } catch (Exception ex) {
                try {
                  Intent intent = new Intent();
                  intent.setClassName("com.iqoo.secure",
                    "com.iqoo.secure.ui.phoneoptimize.BgStartUpManager");
                  startActivity(intent);
                } catch (Exception exx) {
                  ex.printStackTrace();
                }
              }
            }
          }
        })
        .show();
    }
  }
Shivam Oberoi
  • 1,374
  • 1
  • 6
  • 15
1

If have a problem with a specific OEMs, please open an issue on the Android issuetracker as this maybe a CDD violation. Google can contact the OEM and request that they fix the ROM. This is going to take time, in the meanwhile, you can take a look at sites like don't kill my app to understand what are the constraints on a specific device and use a library like autostarter to help the user to navigate to the right setting.

pfmaggi
  • 4,728
  • 16
  • 37