如何启动所有Android制造商的Power Manager以启用后台和推送通知?

Xan*_*Xan 23 android power-management push-notification

一些Android设备由于定制的Android调整由制造商完成,有一些关于电源管理的政治,打破了一些功能,如推送通知.

  • 华为 - 仅限预EMUI 5.0/Android 7 - 转到设置>"受保护的应用",检查您的应用.
  • 索尼 - 点击电池图标.转到电源管理> STAMINA模式>在待机状态下激活的应用>添加您的应用.
  • 华硕 - 在自动启动管理器中检查您的应用程序.
  • 小米 - 安全(应用程序)>权限>自动启动 - 启用您的应用程序
  • *新小米 - 设置>开发人员选项.禁用"内存优化".要启用开发者选项,请转到设置>关于.点击MIUI 8次.
  • Oppo - 转到设置>"安全设置">"数据保存"并启用您的应用.
  • 三星 - 禁用电池使用优化

我想收集意图来启动各自的工具,但我发现只有华为和小米.

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);
Run Code Online (Sandbox Code Playgroud)

我需要其他所有制作人的帮助

Xan*_*Xan 50

我从各种帖子中收集了一些意图:

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"))
};

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

用户同意后

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

我想收集打开电源管理器的所有意图,如果有人发现错误或想改进某些东西,请在这里发表评论

  • 我必须说添加“ com.huawei.permission.external_app_settings.USE_COMPONENT”权限不适用于我的华为P20(AN Pie),但是我发现可以使用`ComponentName(“ com.huawei.systemmanager”,“ com。 huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity“)代替。 (11认同)
  • 我以前的评论中的华为意图不再适用于派。它崩溃并带有SecurityException。 (6认同)
  • 华为在最新版本的EMUI中删除了"受保护的应用程序",转而使用新的活动`com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity`. (5认同)
  • 我添加了这些权限和代码...但是我认为在运行Android 9的华为上,这些权限没有注册。我仍然有一个securityException。还有其他人遇到吗? (4认同)
  • 看起来我们试图实现同一目标。你能检查一下这个Github仓库吗?https://github.com/dirkam/backgroundable-android (2认同)
  • android 9 pie中新的华为电池设置(应用启动)意图是什么? (2认同)
  • @AlexS是的,我完全同意。问题是例如华为在设备不活动12秒后杀死了所有后台活动。甚至前台服务都不能幸免,这太疯狂了。另一件事是,有时它是“禁用”优化,有时是“启用”手动优化。因此,您可能会在应用程序中用措辞误导用户。 (2认同)
  • @SethuramanSrinivasan是的。我在Android 9中启动了另一个活动:new Intent()。setComponent(new ComponentName(“ com.huawei.systemmanager”,“ com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity”)) (2认同)
  • StartupNormalAppListActivity 应该是第一个,除非它崩溃(安全异常)。 (2认同)

Shi*_*roi 7

试试这个代码 - :

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();
    }
  }
Run Code Online (Sandbox Code Playgroud)

  • 谢谢!使用您的信息,我创建了一个[实用工具类](https://gist.github.com/moopat/e9735fa8b5cff69d003353a4feadcdbc)来显示此对话框. (2认同)