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>
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.
Boot receiver is just broadcast receiver which responds to intent with action android.
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:
Open Security app on your phone.
Tap on Permissions, it'll show you two options: Autostart and Permissions
Tap on Autostart, it'll show you list of apps with on or off toggle buttons.
Turn on toggle of your app, you're done!
Now, reboot your phone, you'll see a Toast message I am Running
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With