简体   繁体   English

以编程方式自动启动权限

[英]Autostart permission programmatically

I am working on an app where I need to ask user for the autostart permission and for that I am opening the Autostart permissions settings page for the user to turn on the permission for our app using following code for few Manufacturers:我正在开发一个应用程序,我需要向用户询问自动启动权限,为此我打开了自动启动权限设置页面,让用户使用以下代码为少数制造商打开我们应用程序的权限:

Intent autostartIntent = new Intent();
    if ("xiaomi".equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
       autostartIntent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
       startActivity(autostartIntent);
    } else if ("oppo".equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
       autostartIntent.setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity"));
       startActivity(autostartIntent);
    } else if ("vivo".equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
       autostartIntent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
       startActivity(autostartIntent);
    } else if ("huawei".equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
       autostartIntent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
       startActivity(autostartIntent);
}

Moreover, when I am trying to redirect user to the following devices, I am facing following difficulties:此外,当我尝试将用户重定向到以下设备时,我面临以下困难:

  1. On RealMe 2 Pro, for which the manufacturer is Oppo, the system is unable to start the AutoStart Permissions Activity.在制造商为 Oppo 的 RealMe 2 Pro 上,系统无法启动 AutoStart Permissions Activity。

  2. On Moto and Nokia devices, I am not able to get the path of AutoStart Activity, so that I can redirect user to that page directly.在 Moto 和 Nokia 设备上,我无法获取 AutoStart Activity 的路径,因此我可以将用户直接重定向到该页面。

Found the solution to this question, i am opening the Battery Optimization page for the user to turn off Battery Optimization for my app.找到了这个问题的解决方案,我正在打开电池优化页面,让用户关闭我的应用程序的电池优化。

Here is the code i am using:这是我正在使用的代码:

AlertDialog.Builder builder = new AlertDialog.Builder(PermissionsActivity.this);
    builder.setTitle("Turn off Battery Optimization");
    builder.setMessage("Find XYZ in the list of applications and choose ‘Don’t optimize’.");
    builder.setPositiveButton("Allow",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    if (Build.VERSION.SDK_INT >= 23) {
                        Intent intent = new Intent();
                        intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
                        startActivity(intent);
                    }
                }
            });

    builder.setNegativeButton("Deny", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            finish();
        }
    });
    builder.show();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式检查 MIUI 自动启动权限? - How to check MIUI autostart permission programmatically? 如何在 android studio 上以编程方式检查自动启动权限是启用还是禁用 - how to check Programmatically AutoStart Permission is Enable or disable on android studio 如何在三星设备中以编程方式启用自动启动选项? - How to Enable Autostart option programmatically in Samsung devices? 如何在没有用户许可的情况下自动自动启动android应用? - How to autostart android app automatically without user permission? 如何允许自动启动权限,例如用于离子应用程序的whatapp应用程序 - how to allow autostart permission like whatapp app for ionic application 如何检查应用程序是MI安全权限自动启动中的白名单 - How to check application is white list in MI security permission autostart Android - 如何在小米设备中以编程方式启用自动启动选项? - Android - How to Enable Autostart option programmatically in Xiaomi devices? 为了接收通知,如何在Android上定期和以编程方式自动启动应用程序? - In order to receive notifications, how to autostart app periodically and programmatically on Android? 如何以编程方式在RemoteViews中更改ViewFlipper的'android:autoStart'属性? - How to change 'android:autoStart' attribute of ViewFlipper in RemoteViews programmatically? 以编程方式将我的应用程序添加到 android 中的自动启动应用程序列表 - Add my app to AutoStart apps list in android programmatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM