You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android应用无法实现开机自启问题求助

Android开机自启问题排查步骤

针对你在Galaxy Tab S6 Lite上遇到的开机自启失效问题,结合目标设备Android 9的要求,按以下步骤排查:

  • 关闭应用电池优化
    三星One UI的电池优化会拦截后台广播,需手动将应用加入豁免列表:
    设置 → 电池 → 电池优化 → 找到你的应用 → 选择「不优化」

  • 验证广播接收器是否触发
    在StartActivityOnBootReceiver的onReceive方法中添加日志,确认广播是否被系统发送:

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("BootReceiver", "Received action: " + intent.getAction());
        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()) 
            || Intent.ACTION_LOCKED_BOOT_COMPLETED.equals(intent.getAction())
            || Intent.ACTION_QUICKBOOT_POWERON.equals(intent.getAction())) {
            Intent i = new Intent(context, MainActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        }
    }
    

    重启设备后,通过Android Studio的Logcat过滤BootReceiver标签,查看是否有日志输出。如果没有,说明广播被系统拦截;如果有日志但Activity未启动,再排查启动逻辑。

  • 补充锁屏完成广播支持
    部分设备在锁屏状态下不会发送ACTION_BOOT_COMPLETED,而是发送ACTION_LOCKED_BOOT_COMPLETED,需在Manifest的接收器配置中添加该action:

    <receiver android:name=".StartActivityOnBootReceiver"
            android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    
  • 开启应用自启动权限
    三星设备有单独的自启动权限开关,需手动开启:
    设置 → 应用 → 你的应用 → 权限 → 找到「自启动」或「后台启动」权限并启用

  • 确认gradle配置的targetSdkVersion
    确保build.gradle中targetSdkVersion设置为28(对应Android 9),避免高版本SDK带来的额外权限限制:

    android {
        defaultConfig {
            targetSdkVersion 28
            // 其他配置...
        }
    }
    

内容的提问来源于stack exchange,提问作者garrettb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 15:57:29