android - 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");
}
}
}
解决方案
我也有这个问题,发生的事情是华为有一个层,它控制意味着重新启动它们的应用程序。您必须转到设置 -> 电池 -> 自动启动
正如他们在这里提到的那样 Intent BOOT_COMPLETED 在华为设备上不起作用
推荐阅读
- java - 通知总是创建新的活动,而不是恢复以前的活动
- sql - sqlite3 选择同时引用另一列的列
- linux-kernel - 树莓派如何知道要加载哪个设备树 blob (dtb)?
- flutter - 如何处理不需要的小部件构建?
- android - 从 Fragment 更新时,活动布局跳到状态栏后面
- android - Android 在自定义 Preference 类中检测关闭事件
- powershell - Powershell 命令从位置打开并运行命令
- azure-api-management - API Management Premium - 模拟 DR 故障转移
- ios - 删除 Realm 对象会导致一个函数崩溃,而不是另一个函数崩溃
- excel - 带有数据验证列表的组合框