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

前端 未结 3 595
深忆病人
深忆病人 2020-11-27 10:21

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.

相关标签:
3条回答
  • 2020-11-27 10:23

    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.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

    0 讨论(0)
  • 2020-11-27 10:33

    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();
        }
      }
    
    0 讨论(0)
  • 2020-11-27 10:38

    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.

    0 讨论(0)
提交回复
热议问题