Reputation: 3
I am using the foreground service to track the location of the user but it stops on few devices like OPPO VIVO and XIOAMI MIUI.
After reading some article i have tried few things like For OPPO 1: Turning on Startup Manager 2: Turning off Background freeze,Abnormal apps Optimisation and Doze
I would like to run my services in background.
Upvotes: 0
Views: 454
Reputation: 153
Well it happens in all the Chinese devices because they are using the custom OS to optimise their battery performance. That's why the OS kills every process in background when the app is killed. You need to do few things to keep your service running in the background.
First turning on startup functionality as you already did it. You can also achieve this through code.
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);
}
}
Second you need to lock the app in the recent app tray list so that when he swipes all app from the tray your app doesn’t gets killed/swiped.
I hope it helps you.
Upvotes: 2