25

Hi We are working on an android application where we are using reboot receiver in which I am starting few services where I am performaning some network operation.

I figured it out that in some android devices like xiaomi etc reboot receiver is not working.

Earlier I got to know that In HTC devices also it does not work so I added one more intent filter to it <action android:name="android.intent.action.QUICKBOOT_POWERON" /> then it started working fine. Now other phones like xiaomi it's still not working.

What I have to set additionally so it works fine in all the devices without asking user to update any settings manually.

<receiver
    android:name="com.xyz.broadcastreceiver.ServiceStarter"
    android:exported="true" >
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.intent.action.QUICKBOOT_POWERON" />
    </intent-filter>
</receiver>

Thanks in advance.

N Sharma
  • 33,489
  • 95
  • 256
  • 444
  • the QUICKBOOT_POWERON could be the problem, this is only available on some devices.....delete it and try again... – Opiatefuchs Apr 14 '15 at 13:39
  • @Opiatefuchs If I specify two actions in the intent filter then is it means that both are required to fire this event ? – N Sharma Apr 15 '15 at 06:50
  • @Opiatefuchs see this also http://stackoverflow.com/a/21294637 – N Sharma Apr 15 '15 at 06:57
  • I´m not really sure about it,multiple actions can be made in intent filters, but from the API: "It's okay to create a filter that includes more than one instance of , , or . If you do, you simply need to be certain that the component can handle any and all combinations of those filter elements" ... for my understanding, it means, that if a device can´t handle one, it can´t handle the whole intent. So just separate them and make two receivers... – Opiatefuchs Apr 15 '15 at 11:53
  • Have you seen http://stackoverflow.com/questions/35718468/boot-broadcast-receiver-does-not-work-on-xiaomi-devices? – zeeali Mar 03 '16 at 13:24

10 Answers10

10

Xiaomi phones running MIUI have a inbuilt startup apps blocker. Maybe that is interfering with your boot receiver.

Sanket Berde
  • 6,555
  • 4
  • 35
  • 39
  • 1
    Nothing you can do as an app developer really. This is a OS level setting. Similar settings can be used in any rooted devices using some apps like Rom Toolbox and the likes. [link](https://play.google.com/store/apps/details?id=com.jrummy.liberty.toolbox) But if you whitelist your app in the startup blocker, it should still work. – Sanket Berde Jun 16 '15 at 17:11
  • Is there a way to disable it? – milosmns Oct 13 '16 at 14:17
  • @milosmns nothing you can do as an app developer. – Sanket Berde Oct 15 '16 at 14:05
  • Then how samsung SHealth is starting its service after reboot in Xiaomi? – Bilal Bangash Jan 20 '21 at 10:16
7

Ok, let's try again. MIUI has a a built-in Security app. In the Security app there is a 'Startup' section, where the user can configure which app can and which app can't run on startup. Your application is disabled default. Also if you examine your Logcat you can see a "permission denied" message at startup. Put your app manually to the whitelisted apps, unfortunately that is your users can only do.

wyzard
  • 543
  • 5
  • 17
5

There is an internal feature of MIUI which prevents apps from restarting for saving battery & RAM. You have to manually toggle Auto Start option on in order to receive broadcast for BOOT_COMPLETED. Go to Settings> Installed Apps> Your App. Then just toggle on the auto start option. There is no option to prevent this programmatically. Instead, you can inform your app's users if they face problems while using your app (ex: Alarm is not triggering properly), they can enable Auto Start from Settings.

enter image description here

tahsinRupam
  • 6,325
  • 1
  • 18
  • 34
4

Try adding the android.intent.category.DEFAULT category. It is mandatory for implicit intents, but maybe it is being tweaked for some reason in Xiaomi phones and the intent is not passing one of the tests to being received by your application.

droidpl
  • 5,872
  • 4
  • 35
  • 47
  • @droiddl That is an interesting assumption. What makes you think that? Please, provide any logic behind it. Or maybe someone know that for sure? – Johnny Five Dec 20 '19 at 13:20
  • 1
    A fact is that if an intent is not received the test refered in the post is not passing, that is how the intent framework works. The reason why in a certain device it passes, and in another it doesn't is simple, both OS are not working the same way. OS are customized by OEMs, thus if in 'stock' android it works and in Xiaomi it doesn't then the issue is with the customization – droidpl Dec 22 '19 at 18:08
4

Add this in your manifest file in intent-filter

<action android:name="android.intent.action.BOOT_COMPLETED" />
user229044
  • 232,980
  • 40
  • 330
  • 338
Amaresh Jana
  • 732
  • 11
  • 22
3

Xiomi has a reported bug for only using this reciever 5 minutes after the system
actually boot-up -
http://xiaomi.eu/community/threads/alarmmanager-_wakeup-problem.21430/
You can try and add the -

android:enabled="true" and android:exported="true"
even though they should be set to true by default due to manufacturer system changes
it might be different on Xiomi android customized OS.
Just pay attention for their meaning
Since the android:exported="true"
Will let other applications access to your reciever.

sandeepmaaram
  • 4,191
  • 2
  • 37
  • 42
CrazyPixel
  • 41
  • 3
  • what it means `this reciever 5 minutes after the system` ? – N Sharma Apr 19 '15 at 09:51
  • Basically receivers are objects that register to a system service that is responsible to notify by certain parameters in Xiomi's customized OS they probably only do that after certain things are validated such as battery power and so on I am only guessing though. – CrazyPixel Apr 19 '15 at 14:22
3

You need to add

android:enabled="true"

and

android:exported="true"

exported can be false, but it is necessary to include exported.

I think it's a problem with ROM Xiaomi.eu, tested with the dev version, I used the MIUI 6.5.19 Beta version 7.4 on a Xiaomi Redmi Note 2 Prime. I have not checked with the stable version that can not be downloaded at this time for server maintenance. Broadcast receiver doesn't work on boot.

Probe the same app in a Xiaomi Mi 4 with stable Xiaomi Global ROM, MIUI 7.1.2, there worked perfectly after activating the autostart in the manager. Restart and perfectly worked the broadcast receiver and permissions required.

Now, I tested with Xiaomi.EU 7.3 stable, MIUI 7.3.2, Broadcast receiver works fine on boot and reboot. I registered my receiver with autostart in security manager, it doesn't work in ROM dev version. I don't tested with Xiaomi Official ROM Global dev.

My permissions:

<receiver android:name=".service.BootBroadcastReceiver"
  android:enabled="true"
  android:exported="true">
  <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
    <action android:name="android.intent.action.QUICKBOOT_POWERON" />
    <action android:name="android.intent.action.REBOOT"/>
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</receiver>
kirtan403
  • 7,293
  • 6
  • 54
  • 97
1

you should see here. In Xiaomi devices, they block some permissions even if you require it. The only way to slove it is you must allow your app this permission manually.

pbcQuoc
  • 21
  • 1
0

I was suggesting to add android:enabled="true" but it was already offered.

So I can tell you that you first make sure yourself if the receiver registered properly or not. You can also try the other version of registering it - that is doing registration programmatically (preferably in onPause() & onResume()) and see if it's receiving the broadcast message or not.

stdout
  • 2,471
  • 2
  • 31
  • 40
0

Try to disable the MUIU Optimization from the Developer Options. It worked for me.

1- Go to Settings

2- Open Additional Settings

3- Open Developer Options

4- Find the Turn on MIUI optimization

5- Disable the switch button.

Khalid Taha
  • 3,183
  • 5
  • 27
  • 43