How to enable auto start for an app in xiaomi programmatically

前端 未结 2 1689
滥情空心
滥情空心 2020-12-01 17:10

I would like to know whether the background service for any application can be provided by xiaomi? I have service in my app which need to be running in background all the ti

2条回答
  •  无人及你
    2020-12-01 18:09

    Works for xiaomi, oppo, vivo and oneplus phones as well.

        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"));
            } else if("oneplus".equalsIgnoreCase(manufacturer)) { 
                intent.setComponent(new ComponentName("com.oneplus.security", "com.oneplus.security.chainlaunch.view.ChainLaunchAppListAct‌​ivity")); }
    
            List list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
            if  (list.size() > 0) {
                context.startActivity(intent);
            } 
        } catch (Exception e) {
            Crashlytics.logException(e);
        }
    

提交回复
热议问题