2

I have service in my app which need to be running in background all the time , in all devices its working fine but oppo & vivo not working, i have read some where that we need to enable auto start in settings for app to keep service running

So please tell me how o enable auto start programmatically because user will never do that.

i tried this code but not working.

 try {
    Intent intent = new Intent();
    String manufacturer = android.os.Build.MANUFACTURER;
    if ("xiaomi".equalsIgnoreCase(manufacturer)) {
        intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
    } else if ("oppo".equalsIgnoreCase(manufacturer)) {
        intent.setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity"));
    } else if ("vivo".equalsIgnoreCase(manufacturer)) {
        intent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
    }

    List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    if  (list.size() > 0) {
        context.startActivity(intent);
    } 
} catch (Exception e) {
    Crashlytics.logException(e);
}
Ramesh Yogu
  • 49
  • 1
  • 11
  • this also tried but not working – Ramesh Yogu Feb 15 '18 at 05:27
  • There are no standard API for this right now . So you need to search. – ADM Feb 15 '18 at 05:29
  • For miui, you cannot do that programatically (without opening security center). I heard that, some developer send his application to xiaomi, to analyze it and add automatically to whitelist (like autostart enabled for facebook by default). But they never responded. So you have to open security app to enable that. – Aswin P Ashok Feb 15 '18 at 05:38
  • 3
    **java.lang.SecurityException: Permission Denial: starting Intent { cmp=com.coloros.safecenter/.startupapp.StartupAppListActivity } from ProcessRecord{7eba0ba 27527:crb.call.follow.mycrm/u0a229} (pid=27527, uid=10229) requires oppo.permission.OPPO_COMPONENT_SAFE** this error displayed – Ramesh Yogu Feb 15 '18 at 06:31
  • I made an app which has a foreground service and installed the app in a vivo device. When I try the code above, it successfully points to the settings of auto start applications but my application is not in the list. How can my app be in the autostart settings? – Archie G. Quiñones Jan 07 '19 at 06:11

0 Answers0