Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Foreground service killed in Doze mode for some devices like oppo,vivo,MI, etc

I am using a foreground service to track the live location of the user. it is working fine in stock android devices, but in brands like oppo, vivo, Mi etc, the app is killed when the device comes into doze mode. I also tried to use FCM notifications still of no use. I am just wondering has Uber or Ola been able to crack this, bcuz i have seen most of the drivers have been using these brands. How are the able to keep their app alive in doze mode?

like image 506
Amitabh Avatar asked Sep 11 '25 21:09

Amitabh


1 Answers

you need enable auto start permission for apps in oppo , vivo and mi

try below code worked for me

 private void keepServicesInChineseDevices() {
        Intent intent = new Intent();

        String manufacturer = android.os.Build.MANUFACTURER;

        switch (manufacturer) {

            case "xiaomi":
                intent.setComponent(new ComponentName("com.miui.securitycenter",
                        "com.miui.permcenter.autostart.AutoStartManagementActivity"));
                break;
            case "oppo":
                intent.setComponent(new ComponentName("com.coloros.safecenter",
                        "com.coloros.safecenter.permission.startup.StartupAppListActivity"));

                break;
            case "vivo":
                intent.setComponent(new ComponentName("com.vivo.permissionmanager",
                        "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
                break;
        }

        List<ResolveInfo> arrayList = getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);

        if (arrayList.size() > 0) {
            AppDataHolder.getSession(MyApplication.getAppContext()).setPermissionForChineseDevices(true);
            startActivity(intent);
        }
    }

this article is also helpful

like image 76
akshay_shahane Avatar answered Sep 13 '25 11:09

akshay_shahane