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

前端 未结 3 611
深忆病人
深忆病人 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: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();
        }
      }
    

提交回复
热议问题