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>
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.