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

AAOS Android14 Launcher开发:永久隐藏系统栏与替换启动屏问题

AAOS Android 14 Launcher 永久隐藏系统栏及替换启动屏解决方案

问题1:休眠唤醒后导航栏短暂显示

当前实现仅在Activity生命周期回调中隐藏系统栏,窗口附着后系统可能短暂恢复导航栏显示。需从系统窗口属性、InsetsController行为及生命周期时机三个维度优化:

1. 增强隐藏逻辑,锁定系统栏行为

修改hideSystemBars方法,添加Window Flags并设置InsetsController为永久隐藏模式:

private fun hideSystemBars(window: Window, decorView: View) {
    val insetsController = WindowCompat.getInsetsController(window, decorView)
    // 设置系统栏永不显示,屏蔽手势唤起
    insetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_NEVER_HIDE
    insetsController.hide(WindowInsetsCompat.Type.systemBars())
    
    // 添加全屏Flags,确保窗口占满屏幕
    window.setFlags(
        WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN
    )
    window.setFlags(
        WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
        WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
    )
    
    // 关闭DecorView适配系统窗口,避免预留系统栏空间
    WindowCompat.setDecorFitsSystemWindows(window, false)
}

2. 提前执行隐藏逻辑

将隐藏逻辑移至onAttachedToWindow,这个时机早于onCreate,能在窗口附着到系统时立即锁定全屏:

override fun onAttachedToWindow() {
    super.onAttachedToWindow()
    hideSystemBars(window, window.decorView)
}

3. 优化主题配置

修改themes.xml,增强全屏属性适配AAOS:

<resources>
    <style name="Theme.CarLauncher" parent="android:Theme.DeviceDefault.NoActionBar.Fullscreen">
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
    </style>
</resources>

问题2:重启时默认启动屏显示,Home应用加载延迟

AAOS重启时的默认启动屏("Starting phone...")由SystemUI或BootProgress模块控制,普通应用无法直接替换,需将应用升级为系统级应用并优化启动时机:

1. 配置系统级应用属性

将应用放入AAOS系统的/system/priv-app目录(需编译系统镜像或通过adb push并修改权限),并在AndroidManifest.xml中添加系统级属性:

<application
    ...
    android:persistent="true" <!-- 系统应用专属,保持应用开机驻留 -->
    android:excludeFromRecents="true">
    <activity
        ...
        android:launchMode="singleInstance"
        android:finishOnTaskLaunch="false">
        ...
    </activity>
</application>

2. 监听开机广播,提前启动Launcher

添加开机广播权限及接收器,在系统解锁前(LOCKED_BOOT_COMPLETED)启动Launcher:

第一步:添加权限到Manifest

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.RECEIVE_LOCKED_BOOT_COMPLETED" />

第二步:注册广播接收器

<receiver
    android:name=".BootReceiver"
    android:exported="true"
    android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</receiver>

第三步:实现BootReceiver

class BootReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context?, intent: Intent?) {
        intent ?: return
        if (intent.action in arrayOf(Intent.ACTION_BOOT_COMPLETED, Intent.ACTION_LOCKED_BOOT_COMPLETED)) {
            val launchIntent = Intent(context, CarLauncher::class.java).apply {
                addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
            }
            context?.startActivity(launchIntent)
        }
    }
}

3. 系统层面替换默认启动屏(可选)

若需完全移除"Starting phone..."界面,需修改AAOS系统源码:

  • 禁用SystemUI的BootProgress模块
  • 在device配置中设置PRODUCT_PACKAGES移除默认Launcher,替换为你的应用
  • 配置系统属性跳过启动向导

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 19:25:54