135

I have a Huawei P8 with Android 5.0 that I'm using for testing an app. The app needs to be running in the background, as it tracks BLE regions.

I've discovered that Huawei has built in a "feature" called Protected Apps, that can be accessed from the phone settings (Battery Manager > Protected Apps). This allows elected apps to keep running after the screen is turned off.

Sensibly for Huawei, but unfortunately for me, it looks like it's opt-in, i.e. apps are out by default, and you have to manually put them in. This isn't a showstopper, as I can advise users in an FAQ or printed documentation about the fix, but I recently installed Tinder (for research purposes!), and noticed that it was put in the protected list automatically.

Does anyone know how I can do this for my app? Is it a setting in the manifest? Is it something Huawei has enabled for Tinder because it's a popular app?

shirley
  • 6,207
  • 1
  • 14
  • 32
jaseelder
  • 2,746
  • 3
  • 22
  • 26
  • @agamov, no I couldn't find any more info on it. I just put a line in the description on the Play Store about switching on protected apps. – jaseelder Oct 19 '15 at 09:12
  • @TejasPatel, no I stopped trying to solve it and just informed users in the description – jaseelder Jun 09 '16 at 14:28

7 Answers7

76

There isn't a setting in the manifest, and Huawei has enabled Tinder because it's a popular app. There isn't a way to know if apps are protected.

Anyway I used ifHuaweiAlert() in onCreate() to show an AlertDialog:

private void ifHuaweiAlert() {
    final SharedPreferences settings = getSharedPreferences("ProtectedApps", MODE_PRIVATE);
    final String saveIfSkip = "skipProtectedAppsMessage";
    boolean skipMessage = settings.getBoolean(saveIfSkip, false);
    if (!skipMessage) {
        final SharedPreferences.Editor editor = settings.edit();
        Intent intent = new Intent();
        intent.setClassName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity");
        if (isCallable(intent)) {
            final AppCompatCheckBox dontShowAgain = new AppCompatCheckBox(this);
            dontShowAgain.setText("Do not show again");
            dontShowAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    editor.putBoolean(saveIfSkip, isChecked);
                    editor.apply();
                }
            });

            new AlertDialog.Builder(this)
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .setTitle("Huawei Protected Apps")
                    .setMessage(String.format("%s requires to be enabled in 'Protected Apps' to function properly.%n", getString(R.string.app_name)))
                    .setView(dontShowAgain)
                    .setPositiveButton("Protected Apps", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            huaweiProtectedApps();
                        }
                    })
                    .setNegativeButton(android.R.string.cancel, null)
                    .show();
        } else {
            editor.putBoolean(saveIfSkip, true);
            editor.apply();
        }
    }
}

private boolean isCallable(Intent intent) {
    List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

private void huaweiProtectedApps() {
    try {
        String cmd = "am start -n com.huawei.systemmanager/.optimize.process.ProtectActivity";
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            cmd += " --user " + getUserSerial();
        }
        Runtime.getRuntime().exec(cmd);
    } catch (IOException ignored) {
    }
}

private String getUserSerial() {
    //noinspection ResourceType
    Object userManager = getSystemService("user");
    if (null == userManager) return "";

    try {
        Method myUserHandleMethod = android.os.Process.class.getMethod("myUserHandle", (Class<?>[]) null);
        Object myUserHandle = myUserHandleMethod.invoke(android.os.Process.class, (Object[]) null);
        Method getSerialNumberForUser = userManager.getClass().getMethod("getSerialNumberForUser", myUserHandle.getClass());
        Long userSerial = (Long) getSerialNumberForUser.invoke(userManager, myUserHandle);
        if (userSerial != null) {
            return String.valueOf(userSerial);
        } else {
            return "";
        }
    } catch (NoSuchMethodException | IllegalArgumentException | InvocationTargetException | IllegalAccessException ignored) {
    }
    return "";
}
CopsOnRoad
  • 109,635
  • 30
  • 367
  • 257
Aiuspaktyn
  • 920
  • 1
  • 13
  • 15
  • 7
    how did you find the class name "com.huawei.systemmanager.optimize.process.ProtectActivity"? I'd like to implement something similar for Stamina mode on Sony but don't know the package name of Stamina and class name of "except apps" screen in Stamina settings. – David Riha Mar 20 '16 at 16:25
  • 2
    If package name and class name are known you can easily open the screen, with an intent. Code below. Intent intent = new Intent(); intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity")); startActivity(intent); – kinsell Aug 30 '16 at 07:49
  • 1
    David, your best bet is the logCat. Just move to the settings page and keep the logCat open. – Skynet Feb 24 '17 at 08:14
  • To check if your app is in protected apps list, sample way is install app and check it in app "Phone manager" -> battery manager or protected apps list – ymin Feb 24 '17 at 09:12
  • which class i put this method launcher activity or another classes? – Hari May 04 '17 at 13:56
  • 1
    Can I set power intensive for my application? – sonnv1368 Jun 30 '17 at 03:05
  • Which parameter needs to introduce at getSystemService("user") in place of user, I tried Context.ACCESSIBILITY_SERVICE but not succeeded. – shehzy Jan 11 '18 at 19:12
  • 5
    Correct package name for Huawei P20: com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity – rsicarelli Jul 12 '18 at 20:40
  • P30: you cannot start it with startActivity(): "requires com.huawei.permission.external_app_settings.USE_COMPONENT" – chksr Feb 19 '20 at 17:58
40

+1 for Pierre for his great solution which works for multiple device Manufacturers (Huawei, asus, oppo ...).

I wanted to use his code in my Android app which is in Java. I inspired my code from Pierre and Aiuspaktyn answers.

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Build;
import android.support.v7.widget.AppCompatCheckBox;
import android.widget.CompoundButton;
import java.util.List;

public class Utils {

public static void startPowerSaverIntent(Context context) {
    SharedPreferences settings = context.getSharedPreferences("ProtectedApps", Context.MODE_PRIVATE);
    boolean skipMessage = settings.getBoolean("skipProtectedAppCheck", false);
    if (!skipMessage) {
        final SharedPreferences.Editor editor = settings.edit();
        boolean foundCorrectIntent = false;
        for (Intent intent : Constants.POWERMANAGER_INTENTS) {
            if (isCallable(context, intent)) {
                foundCorrectIntent = true;
                final AppCompatCheckBox dontShowAgain = new AppCompatCheckBox(context);
                dontShowAgain.setText("Do not show again");
                dontShowAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        editor.putBoolean("skipProtectedAppCheck", isChecked);
                        editor.apply();
                    }
                });

                new AlertDialog.Builder(context)
                        .setTitle(Build.MANUFACTURER + " Protected Apps")
                        .setMessage(String.format("%s requires to be enabled in 'Protected Apps' to function properly.%n", context.getString(R.string.app_name)))
                        .setView(dontShowAgain)
                        .setPositiveButton("Go to settings", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                context.startActivity(intent);
                            }
                        })
                        .setNegativeButton(android.R.string.cancel, null)
                        .show();
                break;
            }
        }
        if (!foundCorrectIntent) {
            editor.putBoolean("skipProtectedAppCheck", true);
            editor.apply();
        }
    }
}

private static boolean isCallable(Context context, Intent intent) {
    try {
        if (intent == null || context == null) {
            return false;
        } else {
            List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
                    PackageManager.MATCH_DEFAULT_ONLY);
            return list.size() > 0;
        }
    } catch (Exception ignored) {
        return false;
    }
}
}

}

import android.content.ComponentName;
import android.content.Intent;
import java.util.Arrays;
import java.util.List;

public class Constants {
//updated the POWERMANAGER_INTENTS 26/06/2019
static final List<Intent> POWERMANAGER_INTENTS = Arrays.asList(
        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.optimize.process.ProtectActivity")),
        new Intent().setComponent(new ComponentName("com.huawei.systemmanager", Build.VERSION.SDK_INT >= Build.VERSION_CODES.P? "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity": "com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity")),
        new Intent().setComponent(new ComponentName("com.coloros.oppoguardelf", "com.coloros.powermanager.fuelgaue.PowerUsageModelActivity")),
        new Intent().setComponent(new ComponentName("com.coloros.oppoguardelf", "com.coloros.powermanager.fuelgaue.PowerSaverModeActivity")),
        new Intent().setComponent(new ComponentName("com.coloros.oppoguardelf", "com.coloros.powermanager.fuelgaue.PowerConsumptionActivity")),
        new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity")),
        Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.startupapp.StartupAppListActivity")).setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).setData(Uri.parse("package:"+ MyApplication.getContext().getPackageName())) : null,
        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.asus.mobilemanager", "com.asus.mobilemanager.entry.FunctionActivity")),
        new Intent().setComponent(new ComponentName("com.asus.mobilemanager", "com.asus.mobilemanager.autostart.AutoStartActivity")),
        new Intent().setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity"))
                .setData(android.net.Uri.parse("mobilemanager://function/entry/AutoStart")),
        new Intent().setComponent(new ComponentName("com.meizu.safe", "com.meizu.safe.security.SHOW_APPSEC")).addCategory(Intent.CATEGORY_DEFAULT).putExtra("packageName", BuildConfig.APPLICATION_ID)
);
}

Add the following permissions in your Android.Manifest

<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-permission android:name="oppo.permission.OPPO_COMPONENT_SAFE"/>
<uses-permission android:name="com.huawei.permission.external_app_settings.USE_COMPONENT"/>

  • I am still facing few issues with OPPO devices

I hope this helps someone.

OussaMah
  • 769
  • 8
  • 18
  • 3
    works good. Now, huawei seem like it is not using the PretectedApp setting anymore. It looks like it is using an option called "Launch - Manage app launches and background running to save power" where you have to allow apps to be "auto-launch", "Secondary launch" and "Run in background". Any idea what is this intent? – Ton Sep 13 '18 at 08:23
  • I am glad that it worked for you :). Sorry, i have no idea about the new Huawei feature you mentioned. i should search about it, otherwise my apps would have a problem. – OussaMah Sep 13 '18 at 13:18
  • 5
    @Ton use this: com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity – Simon Oct 06 '18 at 01:05
  • 2
    Change Asus to ComponentName("com.asus.mobilemanager","com.asus.mobilemanager.autostart.AutoStartActivity") – Cristian Cardoso Oct 15 '18 at 00:53
  • 4
    Change Huawei phones above EMUI +5: new Intent().setComponent(new ComponentName("com.huawei.systemmanager", Build.VERSION.SDK_INT >= Build.VERSION_CODES.P? "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity": "com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity")), – Alex Cuadrón Aug 23 '19 at 19:31
  • Read this https://stackoverflow.com/questions/44862176/request-ignore-battery-optimizations-how-to-do-it-right `` may get you banned – beginner Feb 24 '21 at 09:47
36
if("huawei".equalsIgnoreCase(android.os.Build.MANUFACTURER) && !sp.getBoolean("protected",false)) {
        AlertDialog.Builder builder  = new AlertDialog.Builder(this);
        builder.setTitle(R.string.huawei_headline).setMessage(R.string.huawei_text)
                .setPositiveButton(R.string.go_to_protected, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Intent intent = new Intent();
                        intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
                        startActivity(intent);
                        sp.edit().putBoolean("protected",true).commit();
                    }
                }).create().show();
    }
Eran Katsav
  • 1,254
  • 15
  • 15
  • 1
    Until there is a way of knowing if the app got protected or not, this is the best thing, but to avoid showing it every time, I have a "do not show again" and the message is a "You may be charged more if you don't protect" and the actions are "ignore, I'll risk it", or the "go to settings" – Saik Caskey Sep 25 '17 at 10:35
  • 1
    there is somthing similar for ASUS Auto-start Manager ? – Xan Jan 09 '18 at 09:22
  • 3
    Yes, @Xan. Just create the component name as follows: `ComponentName("com.asus.mobilemanager","com.asus.mobilemanager.autostart.AutoStartActivity"));` – Michel Fortes Feb 06 '18 at 10:24
  • 3
    could you explain where is the "sp" object coming from please? as used here? `sp.edit().putBoolean("protected",true).commit();` since I understand that's where you're changing the value to protected right? – Leonardo G. May 02 '18 at 18:31
  • 2
    @LeonardoG. : quite sure that "sp" stands for SharedPreferences, final SharedPreferences sp = getSharedPreferences("ProtectedApps", Context.MODE_PRIVATE); – papesky Jul 28 '18 at 16:22
18

Solution for all devices (Xamarin.Android)

Usage:

MainActivity =>
protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);

    MyUtils.StartPowerSaverIntent(this);
}

public class MyUtils
{
    private const string SKIP_INTENT_CHECK = "skipAppListMessage";

    private static List<Intent> POWERMANAGER_INTENTS = new List<Intent>()
    {
        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.appcontrol.activity.StartupAppControlActivity")),
        new Intent().SetComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity")),
        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.autostart.AutoStartActivity")),
        new Intent().SetComponent(new ComponentName("com.asus.mobilemanager", "com.asus.mobilemanager.entry.FunctionActivity")).SetData(Android.Net.Uri.Parse("mobilemanager://function/entry/AutoStart")),
        new Intent().SetComponent(new ComponentName("com.dewav.dwappmanager", "com.dewav.dwappmanager.memory.SmartClearupWhiteList"))
    };

    public static void StartPowerSaverIntent(Context context)
    {
        ISharedPreferences settings = context.GetSharedPreferences("ProtectedApps", FileCreationMode.Private);
        bool skipMessage = settings.GetBoolean(SKIP_INTENT_CHECK, false);
        if (!skipMessage)
        {
            bool HasIntent = false;
            ISharedPreferencesEditor editor = settings.Edit();
            foreach (Intent intent in POWERMANAGER_INTENTS)
            {
                if (context.PackageManager.ResolveActivity(intent, PackageInfoFlags.MatchDefaultOnly) != null)
                {
                    var dontShowAgain = new Android.Support.V7.Widget.AppCompatCheckBox(context);
                    dontShowAgain.Text = "Do not show again";
                    dontShowAgain.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) =>
                    {
                        editor.PutBoolean(SKIP_INTENT_CHECK, e.IsChecked);
                        editor.Apply();
                    };

                    new AlertDialog.Builder(context)
                    .SetIcon(Android.Resource.Drawable.IcDialogAlert)
                    .SetTitle(string.Format("Add {0} to list", context.GetString(Resource.String.app_name)))
                    .SetMessage(string.Format("{0} requires to be enabled/added in the list to function properly.\n", context.GetString(Resource.String.app_name)))
                    .SetView(dontShowAgain)
                    .SetPositiveButton("Go to settings", (o, d) => context.StartActivity(intent))
                    .SetNegativeButton(Android.Resource.String.Cancel, (o, d) => { })
                    .Show();

                    HasIntent = true;

                    break;
                }
            }

            if (!HasIntent)
            {
                editor.PutBoolean(SKIP_INTENT_CHECK, true);
                editor.Apply();
            }
        }
    }
}

Add the following permissions in your Android.Manifest

<uses-permission android:name="oppo.permission.OPPO_COMPONENT_SAFE"/>
<uses-permission android:name="com.huawei.permission.external_app_settings.USE_COMPONENT"/>

To help find the activity of the device not listed here, simply use the following method to help find the correct activity to open for the user

C#

public static void LogDeviceBrandActivities(Context context)
{
    var Brand = Android.OS.Build.Brand?.ToLower()?.Trim() ?? "";
    var Manufacturer = Android.OS.Build.Manufacturer?.ToLower()?.Trim() ?? "";

    var apps = context.PackageManager.GetInstalledPackages(PackageInfoFlags.Activities);

    foreach (PackageInfo pi in apps.OrderBy(n => n.PackageName))
    {
        if (pi.PackageName.ToLower().Contains(Brand) || pi.PackageName.ToLower().Contains(Manufacturer))
        {
            var print = false;
            var activityInfo = "";

            if (pi.Activities != null)
            {
                foreach (var activity in pi.Activities.OrderBy(n => n.Name))
                {
                    if (activity.Name.ToLower().Contains(Brand) || activity.Name.ToLower().Contains(Manufacturer))
                    {
                        activityInfo += "  Activity: " + activity.Name + (string.IsNullOrEmpty(activity.Permission) ? "" : " - Permission: " + activity.Permission) + "\n";
                        print = true;
                    }
                }
            }

            if (print)
            {
                Android.Util.Log.Error("brand.activities", "PackageName: " + pi.PackageName);
                Android.Util.Log.Warn("brand.activities", activityInfo);
            }
        }
    }
}

Java

public static void logDeviceBrandActivities(Context context) {
    String brand = Build.BRAND.toLowerCase();
    String manufacturer = Build.MANUFACTURER.toLowerCase();

    List<PackageInfo> apps = context.getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);

    Collections.sort(apps, (a, b) -> a.packageName.compareTo(b.packageName));
    for (PackageInfo pi : apps) {
        if (pi.packageName.toLowerCase().contains(brand) || pi.packageName.toLowerCase().contains(manufacturer)) {
            boolean print = false;
            StringBuilder activityInfo = new StringBuilder();

            if (pi.activities != null && pi.activities.length > 0) {
                List<ActivityInfo> activities = Arrays.asList(pi.activities);

                Collections.sort(activities, (a, b) -> a.name.compareTo(b.name));
                for (ActivityInfo ai : activities) {
                    if (ai.name.toLowerCase().contains(brand) || ai.name.toLowerCase().contains(manufacturer)) {
                        activityInfo.append("  Activity: ").append(ai.name)
                                .append(ai.permission == null || ai.permission.length() == 0 ? "" : " - Permission: " + ai.permission)
                                .append("\n");
                        print = true;
                    }
                }
            }

            if (print) {
                Log.e("brand.activities", "PackageName: " + pi.packageName);
                Log.w("brand.activities", activityInfo.toString());
            }
        }
    }
}

Execute on startup and search through the log file, add a logcat filter on TAG of brand.activities

MainActivity =>
protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);

    MyUtils.LogDeviceBrandActivities(this);
}

Sample Output:

E/brand.activities: PackageName: com.samsung.android.lool
W/brand.activities: ...
W/brand.activities:   Activity: com.samsung.android.sm.ui.battery.AppSleepSettingActivity
W/brand.activities:   Activity: com.samsung.android.sm.ui.battery.BatteryActivity <-- This is the one...
W/brand.activities:   Activity: com.samsung.android.sm.ui.battery.BatteryActivityForCard
W/brand.activities: ...

So the component name will be:

new ComponentName("<PackageName>", "<Activity>")
new ComponentName("com.samsung.android.lool", "com.samsung.android.sm.ui.battery.BatteryActivity")

If the activity has a permission next to it, the following entry in the Android.Manifest is required to open the activity:

<uses-permission android:name="<permission>" />

Comment or edit the new component into this answer. All help will me much appreciated.

Pierre
  • 6,347
  • 4
  • 48
  • 67
  • how did you find the class name "com.huawei.systemmanager.optimize.process.ProtectActivity"? I'd like to implement something similar for Qmobile but don't know the package name of Qmobile and class name of "except apps" screen – Noaman Akram Mar 20 '19 at 10:17
  • 1
    You can edit in your answer about Qmobile .. new Intent().setComponent(new ComponentName( "com.dewav.dwappmanager", "com.dewav.dwappmanager.memory.SmartClearupWhiteList")), – Noaman Akram Mar 20 '19 at 23:35
  • I have used this code but its not working in Samsung J6 mobile. – Shailesh May 15 '19 at 13:40
  • @Pierre have you considered making this into a library on GitHub so that other projects can include it directly? Other developers can also then contribute new components via pull requests. Thoughts? – Shankari May 11 '20 at 14:03
2

You can use this library to navigate the user to protected apps or autostart:

AutoStarter

If the phone supports autostart feature you can show to the user a hint to enable your app in these apps

You can check by this method:

AutoStartPermissionHelper.getInstance().isAutoStartPermissionAvailable(context)

And for navigating the user to that page, simply call this:

AutoStartPermissionHelper.getInstance().getAutoStartPermission(context)
Amir Hossein Ghasemi
  • 7,952
  • 4
  • 43
  • 42
1

I'm using @Aiuspaktyn solution which is missing the part of how to detect when stop show the dialog after the user set the app as protected. I'm use a Service to check if the app was terminated or not, checking if it exists.

oikumo
  • 21
  • 3
-4

PowerMaster -> AutoStart ->Find your app in blocked section and allow

gdarcan
  • 484
  • 5
  • 7