Boot BroadcastReceiver 不适用于小米设备 [英] Boot BroadcastReceiver does not work on Xiaomi devices

本文介绍了Boot BroadcastReceiver 不适用于小米设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 BroadcastReceiver 应该在启动完成后运行.我已经在我的 小米设备 (Redmi 1s) 上对其进行了测试,它没有运行,而在其他设备(如 三星)上,它按预期运行.

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();
        }
    }
}

我在 Manifest 中设置了权限.

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:

  1. 在您的手机上打开安全应用.

点按权限,它会显示两个选项:自动启动和权限

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!

现在,重启你的手机,你会看到一条 Toast 消息我正在跑步

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

这篇关于Boot BroadcastReceiver 不适用于小米设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆