Boot BroadcastReceiver does not work on Xiaomi devices

不问归期 提交于 2019-12-28 04:06:34

问题


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>

回答1:


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



来源:https://stackoverflow.com/questions/35718468/boot-broadcastreceiver-does-not-work-on-xiaomi-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!