0

I have huawei phone and when I use foreground service on huawei its just stop the service. However, I found this solution ( https://stackoverflow.com/a/51726040/14446860 ). Because my app isn't enable in the protected apps on my huawei phone,the service stop.

My question is, How can I broadcast this setting when I am asking the user to enable protected app? Do I have to ask the user every time even he enable it ?

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

Thank you.

Mr.Goomer
  • 73
  • 7

1 Answers1

1

UPDATE

  1. The EMUI supports jumping from the app UI to the app startup management page, but does not provide an interface for checking whether the app is kept alive in the background.
  2. Therefore, it is recommended to display a prompt instead of jumping to the system.
  • When the app is started for the first time, a prompt displayed to instruct users to manually keep the app alive in the background.
  • If background keepalive is not enabled, the app cannot run in the background for a long time. You are advised to use FAQs to notify users of the problem in your app.

This experience may not be the best. However, to ensure the power consumption and performance of phone, Huawei does not provide related interfaces.


This is to prevent malicious operations such as background running and associated startup, which may cause a sharp increase in your phone's memory and power consumption. By default, the EMUI does not allow related apps to be kept alive in the background or associated with the phone. However, it supports manual keepalive in the associated phone, so that the apps can be powered on or automatically started in the background, and the settings take effect after the phone is restarted.

If the application needs to be allowed in the background all the time due to the usage scenario, we suggest that when the application is launched for the first time after installation, a pop-up prompt instructs the user to perform manual keep-alive operation.

You can do that by following steps: Phone Manager → Application Launch Management → Close Auto Management → Select Allow Self Launch / Allow Background Activity.

The pop-up suggests that the application needs to do a small amount of development accordingly.

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
  • First of all thank you very much for your detailed reply. What about old people and people who its their first time doing it?Can I set a broadcast to detect if they enabled it and transfer them to main activity ? – Mr.Goomer Feb 05 '21 at 12:30
  • hi @Goomer,i updated my answer,pls kindly refer,Thank you for understanding! – zhangxaochen Feb 08 '21 at 02:05