引导BroadcastReceiver在小米设备上不起作用 [英] Boot BroadcastReceiver does not work on Xiaomi devices

本文介绍了引导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();
        }
    }
}

我已在清单中设置权限.

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

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

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