1

Hello I used this code for start Autostart permission in android mi,oppo,vivo device.this perfect running, but how to know autostart permission allowed by user.

private void addAutoStartup() {

    try {
        Intent intent = new Intent();
        String manufacturer = android.os.Build.MANUFACTURER;
        if ("xiaomi".equalsIgnoreCase(manufacturer)) {
            intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
        } else if ("oppo".equalsIgnoreCase(manufacturer)) {
            intent.setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity"));
        } else if ("vivo".equalsIgnoreCase(manufacturer)) {
            intent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
        } else if ("Letv".equalsIgnoreCase(manufacturer)) {
            intent.setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity"));
        } else if ("Honor".equalsIgnoreCase(manufacturer)) {
            intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
        }

        List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        if (list.size() > 0) {
            startActivityForResult(intent, 1);
            startActivity(intent);
        }
    } catch (Exception e) {
        Log.e("exc", String.valueOf(e));
    }
}

How to find out if this permission allowed or not?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

1

Short answer you can't

As of now it can be done via root but it is not recommended and can potentially harm user's device . As for me i tend to create a dialog and redirect user to autostart screen. If user click on "do not show again(checkbox)" simply stop showing that dialog but consider this as a liable option but bad practice

Permission Dialog

Kishan Thakkar
  • 429
  • 4
  • 11