Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boot BroadcastReceiver does not work on Xiaomi devices

I have a following BroadcastReceiver which should run after boot completion. I have tested it on my Xiaomi device (Redmi 1s), it's not running, while on other devices like Samsung it's running as expected.

public class DeviceBootReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
            Toast.makeText(context, "I am Running", Toast.LENGTH_SHORT).show();
        }
    }
}

I have set permission in Manifest.

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

And following is my broadcast receiver:

<receiver android:name=".receiver.DeviceBootReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
    </intent-filter>
</receiver>
like image 556
zeeali Avatar asked Mar 01 '16 09:03

zeeali


People also ask

What is android boot receiver?

public class BootReceiver extends android.content.BroadcastReceiver. Implements a BroadcastReceiver for BOOT_COMPLETED for enabling location monitoring when the device starts if and only if location monitoring was enabled when the device powered off.

What is boot receiver in mobile phone?

Boot receiver is just broadcast receiver which responds to intent with action android.


1 Answers

I searched around the web and found a solution, I've decided to answer my own question. Follow the same code given in the question.

In Xiaomi devices, you just have to add your app to Autostart list, to do so, follow these simple steps given below:

  1. Open Security app on your phone.

  2. Tap on Permissions, it'll show you two options: Autostart and Permissions

  3. Tap on Autostart, it'll show you list of apps with on or off toggle buttons.

  4. Turn on toggle of your app, you're done!

Now, reboot your phone, you'll see a Toast message I am Running

like image 169
zeeali Avatar answered Oct 04 '22 19:10

zeeali