首页 > 解决方案 > BOOT_COMPLETED 不适用于华为设备

问题描述

我注意到我的华为测试设备(华为 P20)没有检测到动作 BOOT_COMPLETED,而其他测试设备可以(三星...)。我知道添加我的应用程序保护不足的应用程序(手动模式)可以解决我的问题,但我的最终用户不知道如何添加应用程序保护不足的应用程序。有没有办法在不添加应用程序受保护的应用程序(手动模式)的情况下检测系统启动?

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
<receiver android:name=".recivers.BootBroadcastReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.intent.action.QUICKBOOT_POWERON" />
    </intent-filter>
</receiver>

接收者:

public class BootBroadcastReceiver extends BroadcastReceiver {

    private static final String TAG = "BootBroadcastReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {

        String action = intent . getAction ();

        if (action != null && action.equals(Intent.ACTION_BOOT_COMPLETED)) {

            Toast.makeText(context, "BOOT", Toast.LENGTH_LONG).show();
            Log.e(TAG, "BOOT");

        }

    }
}

标签: androidhuawei-mobile-services

解决方案


我也有这个问题,发生的事情是华为有一个层,它控制意味着重新启动它们的应用程序。您必须转到设置 -> 电池 -> 自动启动

正如他们在这里提到的那样 Intent BOOT_COMPLETED 在华为设备上不起作用


推荐阅读