Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable auto start for an app in xiaomi programmatically

Tags:

android

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 time , in all devices its working fine except Xiaomi, how it can be done programmatically?

like image 739
Surya Mitra Avatar asked Mar 16 '16 12:03

Surya Mitra


People also ask

How do I allow apps to start automatically?

Select "Manage apps". Alternatively, you can head to Settings > Manage Apps. From the Manage apps page, tap on "Permission" and you'll see the "Autostart" option, so tap on it. You'll be given a list of all the apps that can be made to autostart.

How do I get Miui security app auto start permission programmatically?

You need to give permissions in the in build security application for xiaomi. 1. open the security app 2. go to permissions 3. go to auto start 4. enable the applications that you want to keep running in the background!

How do I set autostart permission in android programmatically?

You can manually check under Security permissions => Autostart => Enable Autostart .


2 Answers

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<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        if  (list.size() > 0) {
            context.startActivity(intent);
        } 
    } catch (Exception e) {
        Crashlytics.logException(e);
    }
like image 188
rajkumar Avatar answered Oct 16 '22 04:10

rajkumar


you wont be able to do that from code until and unless there is some api from xiaomi that gives you access to that functionality. I am guessing auto start manager is an app( with privileges of that of a system app, since part of xiaomi modified os) , hence not possible. On the other-hand if the device is rooted you can actually disable autostart manager.

Still whatsapp , facebook and many more apps doing this may be because of they have tie ups with Xiaomi to be in the whitelist. But its just a guess.

like image 35
Abhi Avatar answered Oct 16 '22 06:10

Abhi