引导广播接收器不会对小蜜设备上工作 [英] Boot Broadcast Receiver does not work on Xiaomi devices

查看:385
本文介绍了引导广播接收器不会对小蜜设备上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下广播接收机开机完成后,应运行。我测试了它在我的小蜜装置(红米手机1S)上,它没有运行,而像三星其他设备如预期它的运行。

 公共类DeviceBootReceiver扩展广播接收器{
    @覆盖
    公共无效的onReceive(上下文的背景下,意图意图){
        如果(intent.getAction()。等于(android.intent.action.BOOT_COMPLETED)){
            Toast.makeText(背景下,我跑,Toast.LENGTH_SHORT).show();
        }
    }
}

我在清单设置权限。

 <使用许可权的android:NAME =android.permission.RECEIVE_BOOT_COMPLETED/>

和以下是我的广播接收器:

 <接收机器人:名字=。receiver.DeviceBootReceiver>
    &所述;意图滤光器>
        <作用机器人:名字=android.intent.action.BOOT_COMPLETED/>
    &所述; /意图滤光器>
< /接收器>


解决方案

我在网上搜索了一圈,发现一个解决方案,我决定回答我的问题。按照这一问题给予同样的code。

小蜜设备,你只需要您的应用程序添加到自动启动列表中,这样做,请执行以下这些简单的步骤:


  1. 打开安全在手机上的应用程序。


  2. 塔上的权限后,它会告诉你两个选项:自动启动和
    权限


  3. 点选自动启动后,它会与开启或关闭切换显示你的应用程序列表
        按钮。


  4. 在您的应用程序的切换打开,你就大功告成了!


现在,重启你的手机,你会看到一个吐司消息的我正在

I have a following Broadcast Receiver which should run after boot completed. 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. 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

这篇关于引导广播接收器不会对小蜜设备上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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