26

My App is working with good remarks in all mobile except MI. Because MI restricting my App background service to run. After enabling App in Autostart in Security, it working perfectly. So can I enable that AutoStart Option for my app in MI Security App through programmatically. Please let me know your valuable suggestions.

And My doubt is how whatsapp , facebook and many more apps default enabling Autostart Option in Security App in Xiaomi?

Thanks in Advance.

Shamili Rani
  • 345
  • 1
  • 4
  • 12
  • Please refer attached link for reference https://stackoverflow.com/questions/49473230/android-how-to-enable-autostart-option-programmatically-in-xiaomi-devices/65827056#65827056 – Abdul Waheed Jan 25 '21 at 06:26

3 Answers3

27

Try this...it's working for me. It will open the screen to enable autostart.

String manufacturer = "xiaomi";
        if(manufacturer.equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
            //this will open auto start screen where user can enable permission for your app
            Intent intent = new Intent();
            intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
            startActivity(intent);
        }
Mohit Mathur
  • 679
  • 8
  • 15
  • 2
    Its working fine, but App is crashing(Automatically closing) if I Enable -> Disabled app from AutoStart list. – Shamili Rani Jan 18 '17 at 12:38
  • Note that I found Redmi Note 3 (Android 5) has annoying bug which Autostart page requires user toggle off -> back -> toggle on to make it work after uninstall then reinstall the app (reinstall without uninstall no such issue). The second bug is if user toggle off the app, it will close the page and exit the app. – 林果皞 Oct 19 '17 at 11:13
  • I detect miui with: `val isMIUI = (Class.forName("android.os.SystemProperties") .getMethod("get", String::class.java) .invoke(null, "ro.miui.ui.version.code") as String? ?: "") != ""` Because, a xiaomi device might not always be running miui, and miui might not always be running on a xiaomi, considering custom roms and unofficial ports, and their recent mi A1 with stock android. – hoshiKuzu Nov 26 '17 at 14:43
  • 2
    Hi all but how to check if autostart permission already enabled or not. Because if we use above code it will call every time – PPD May 28 '18 at 07:38
  • 2
    @PPD how to check autostart permission already enable or not ? – Akash Singh Jun 20 '18 at 18:52
  • 1
    Is there a way to detect whether it is enable or not by user @Mohit Mathur ? – Kishan Solanki Oct 26 '18 at 13:10
  • @AkashSingh, have you got a solution? – Sony Mar 06 '19 at 10:13
  • @KishanSolanki124, any solition for this – Sony Mar 06 '19 at 10:14
  • @Sony sorry, not yet. – Kishan Solanki Mar 06 '19 at 12:15
  • there is no Android API to check if the the AutoStart is enabled or not. Though you can have you logic (may be you can use preference to set a Boolean for it) to check this. Please have a look here : stackoverflow.com/a/56335831/5685911 – Akki Jun 01 '19 at 15:15
10

Facebook, Whatsapp, Messenger and few more popular apps are whitelisted by Xiaomi. Hence they get enabled by default. Other apps need to be enabled by users. We don't have any other option.

We need to programmatically detect the manufacturer using Build.MANUFACTURER in android and show a dialog which suggests the user to enable the app in AutoStart, if the manufacturer is Xiaomi

venkat
  • 517
  • 1
  • 8
  • 29
  • I am facing this issue for long days and also posted in SO https://stackoverflow.com/questions/49473230/android-how-to-enable-autostart-option-programmatically-in-xiaomi-devices.. Can you pls mention some reference links annotating that Xiaomi allows popular apps ? I would like to share the same to our client – Rakesh L Mar 25 '18 at 08:28
  • You can manually check that in any Redmi mobile. You can simply install any Facebook app, it will be whitelisted by default where other apps won't – venkat Mar 27 '18 at 05:01
  • Is there a way to check if the device allows the app to run on boot? – android developer Jan 29 '19 at 11:22
  • No. They don't provide any API to check that. – venkat Jan 29 '19 at 19:06
  • @RakeshL Have you found a solutions for how to check if it is enabled? – Royz Apr 04 '19 at 08:06
  • @Royz As Venkat commented, there is no Android API to check if the the AutoStart is enabled or not. Though you can have you logic (may be you can use preference to set a Boolean for it) to check this. – Akki Jun 01 '19 at 15:14
  • Please refere attached link for reference https://stackoverflow.com/questions/49473230/android-how-to-enable-autostart-option-programmatically-in-xiaomi-devices/65827056#65827056 – Abdul Waheed Jan 25 '21 at 06:27
0

There is some other way. Install Aarogya setu app, app already has Auto-start permission. It seems, there is a way to whitelist apps for Autostart from online portal of manufacturer.