How to start Power Manager of all android manufactures to enable background and push notification?
Asked Answered
B

3

46

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

Branscum answered 9/1, 2018 at 10:32 Comment(0)
B
103

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

Branscum answered 6/2, 2018 at 10:52 Comment(35)
Looks like we try to achieve the same thing. Can you please check this Github repo? github.com/dirkam/backgroundable-androidPachisi
yes, i have collected more intents, you have collected more details. on xiaomi we have found different intentBranscum
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.Pachisi
would you updated this? is it still up to date for Samsung?Fixture
@kilianeller more or less. if anyone post a comment, i will update answerBranscum
Huawei removed its "protected apps" in recent versions of EMUI, in favour of a new activity com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity.Weimer
For HTC, there's Boost+: com.htc.pitroad/.landingpage.activity.LandingPageActivity - then select "manage background apps" (or similar).Pigsty
@Pigsty 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 testBranscum
@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).Pigsty
@Pigsty added to main postBranscum
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 ?Ousel
simple you can'tBranscum
The Huawei intent from my older comment no longer works on pie. It crashes with a SecurityException.Weimer
i cant try now, if you find solution i will update postBranscum
What is the new huawei battery settings (App launch) intent in android 9 Pie?Consensual
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_SAFESkerl
so using "oppo.permission.OPPO_COMPONENT_SAFE" permission works ?Branscum
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 <uses-permission android:name="com.huawei.permission.external_app_settings.USE_COMPONENT"/> in manifest.Trackman
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?Buchan
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.Scrooge
@DavidSucharda added in listBranscum
@DavidSucharda this is so hard for users, i think... but no any other ways exist. Thank you.Hotheaded
@Hotheaded 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.Scrooge
@AlonMinski Did you resolve that security exception issue?Arlin
@himCream Did you resolve that security exception issue?Arlin
@SethuramanSrinivasan yes. I launched a different activity in Android 9: new Intent().setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity"))Buchan
StartupNormalAppListActivity should be first unless it crashes (security exception).Mozzarella
This Gist is a working example, but beware of SecurityExceptions as mentioned in the other comments: gist.github.com/moopat/e9735fa8b5cff69d003353a4feadcdbcSelfeducated
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://mcmap.net/q/358898/-how-to-enable-autostart-option-programmatically-in-samsung-devicesArgentous
For the latest Samsung devices use com.samsung.android.sm.battery.ui.BatteryActivity instead of com.samsung.android.sm.ui.battery.BatteryActivityRebeccarebecka
aggiornato il postBranscum
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://mcmap.net/q/358899/-denial-permission-oppo_component_safeAmoakuh
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.Amoakuh
Hi @Xan first Thanks For this solution, for infinix device what should we use?Swordsman
@Swordsman i don't know, if you find something tell me, i will add on list :)Branscum
P
10

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();
    }
  }
Polygamy answered 9/1, 2018 at 10:35 Comment(3)
You can add in your desired band Build.MANUFACTURER.equalsIgnoreCase("oppo")Polygamy
any help about intent for ASUS ?Branscum
Thank you! Using your information I created a utility class for showing this dialog.Portauprince
Z
4

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.

Zeist answered 30/7, 2020 at 14:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.