Reboot receiver is not working in xiaomi phones
Asked Answered
H

10

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.

Headstream answered 14/4, 2015 at 12:53 Comment(5)
the QUICKBOOT_POWERON could be the problem, this is only available on some devices.....delete it and try again...Swear
@Swear If I specify two actions in the intent filter then is it means that both are required to fire this event ?Headstream
@Swear see this also stackoverflow.com/a/21294637Headstream
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 <action>, <data>, or <category>. 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...Swear
Have you seen #35718968?Alcmene
S
10

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

Steve answered 16/6, 2015 at 16:43 Comment(4)
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 But if you whitelist your app in the startup blocker, it should still work.Steve
Is there a way to disable it?Elmiraelmo
@Elmiraelmo nothing you can do as an app developer.Steve
Then how samsung SHealth is starting its service after reboot in Xiaomi?Destinee
E
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.

Ebro answered 6/8, 2015 at 4:10 Comment(0)
C
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

Cilicia answered 17/9, 2018 at 9:42 Comment(0)
S
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.

System answered 23/4, 2015 at 23:30 Comment(2)
@droiddl That is an interesting assumption. What makes you think that? Please, provide any logic behind it. Or maybe someone know that for sure?Carlacarlee
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 customizationSystem
S
4

Add this in your manifest file in intent-filter

<action android:name="android.intent.action.BOOT_COMPLETED" />
Scummy answered 15/6, 2015 at 13:40 Comment(2)
It's already there <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.QUICKBOOT_POWERON" /> </intent-filter> or you are talking for something elseHeadstream
why does this answer has +50 reputations? Its not a solution in MIUICareen
G
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.

Gardening answered 19/4, 2015 at 9:49 Comment(2)
what it means this reciever 5 minutes after the system ?Headstream
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.Gardening
P
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>
Procumbent answered 28/5, 2016 at 0:9 Comment(2)
Have you any work around? I found that the "schedule power off/on" doesn't send BOOT_COMPLETED on Mi4iHodman
I found to use stable version to fix this problem.Procumbent
E
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.

Emilioemily answered 27/6, 2017 at 23:42 Comment(0)
J
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.

Johore answered 16/6, 2015 at 22:50 Comment(0)
S
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.

Solley answered 18/12, 2018 at 13:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.