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?
-
Are you talking about background service should be active in while app is running? – Ajay Mehta Apr 12 '19 at 13:17
-
Any case whether the app is in background or force closed, the issue occurs in both cases. – Amitabh Apr 12 '19 at 13:39
-
For latest android versions, you can not keep your service keep active in background while app is closed. So you have to start your service as a background. JFYI: I am talking about background Service class. Please check please check my answer here https://stackoverflow.com/questions/55571182/service-stops-working-when-app-gets-closed/55571560#55571560. It might help you. You can also download the sample code to keep your service active while application closed here: https://filebin.net/p5jv54ow5vl4y4gt/ServiceSample.zip?t=p6vqlepa – Ajay Mehta Apr 12 '19 at 13:50
2 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);
}
}

- 4,423
- 2
- 17
- 30
-
1
-
i use forground sticky service but its not working on oppo and realme android devices how can use above solution in my farground service – Asif Mehmood May 21 '20 at 07:04
Thank you so much guys, for your responses. I would like to tell you that I wrote an email to google support and highlighted the issue to google support, in reply they mentioned below reply: "Thanks for reaching out.
It seems that you can’t receive a push notification on some Android devices. Upon checking the affected device, it is affected by a device specific (known) issue, and it's caused by OEM features for battery optimization. When the app is swiped away, in some of OEMs which has implemented such a feature, the application is treated similar to "force-stopped" mechanism and services registered with the app that's swiped, is stopped.
For now, I strongly recommend contacting the support team of those affected OEMs to help get it resolved from their end. You can read more about this issue and a possible way of solving it in this blog post(https://www.freecodecamp.org/news/why-your-push-notifications-never-see-the-light-of-day-3fa297520793/).

- 49
- 3