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

Android智能电视设置界面PIN码锁定应用问题求助:onAccessibilityEvent函数未触发,无法锁定设置界面

Android智能电视设置界面PIN码锁定应用问题求助:onAccessibilityEvent函数未触发,无法锁定设置界面

我正在开发一款面向智能电视的Android应用,核心目标是让应用在后台常驻,通过PIN码验证来拦截系统设置界面的打开——只有用户输入正确的PIN(比如预设的1234),才能正常进入设置。

目前我已经把应用部署到TCL智能电视上,并且在系统的辅助功能设置里手动启用了这个应用,但它完全没有起到锁定设置的效果。之后我换到Android TV(1080p)模拟器上测试,发现一个关键问题:AccessibilityService里的override fun onAccessibilityEvent(event: AccessibilityEvent?)函数从来没有被调用过,这应该就是功能失效的核心原因了。

下面是我目前的相关代码:

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
    <uses-feature android:name="android.software.leanback" android:required="true" />

    <application android:allowBackup="true" android:icon="@drawable/lock" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/Theme.SecureSettings">
        <activity android:name=".MainActivity" android:banner="@drawable/app_logo" android:exported="true" android:icon="@drawable/lock" android:logo="@drawable/lock">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".LockScreenActivity" android:exported="true" android:launchMode="singleTask" android:theme="@style/Theme.AppCompat.NoActionBar"/>
        <service android:name=".AppLockService" android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" android:exported="true">
            <intent-filter>
                <action android:name="android.accessibilityservice.AccessibilityService" />
            </intent-filter>
            <meta-data android:name="android.accessibilityservice" android:resource="@xml/accessibility_service_config" />
        </service>
        <receiver android:name=".BootReceiver" android:enabled="true" android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
    </application>
</manifest>

activity_main.xml(注:代码内容未粘贴完整)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    android:background="@color/black"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/logo"
            android:layout_width="50dp"
            android:layout_height="50dp"
            tools:srcCompat="@drawable/lock" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/app_name"
            android:textColor="@color/white"
            android:textSize="20sp"
            android:textStyle="bold"
            android:layout_marginTop="15dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="16dp"
        android:gravity="center">

        <Button
            android:id="@+id/btn_enable_security"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:text="Enable Security"
            android:textSize="12sp"
            style="@style/Widget.AppCompat.Button.Colored"
            android:padding="10dp" >
        </Button>

        <Button
            android:id="@+id/btn_accessibility"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:text="@string/enable_service"
            android:textSize="12sp"
            style="@style/Widget.AppCompat.Button.Colored">
        </Button>

        <Button android:id="@+id/btn_exit" android:layout_width="wrap_content&

我已经做了这些排查动作:

  • 在辅助功能设置里确认启用了应用的Accessibility Service
  • 清单文件里已经申请了相关权限(包括SYSTEM_ALERT_WINDOW、RECEIVE_BOOT_COMPLETED等)
  • 应用是针对Leanback环境开发的,已经声明了android.software.leanback的feature

现在完全摸不着头绪,有没有朋友能帮我分析下:为什么onAccessibilityEvent函数不会被触发?或者针对Android TV的辅助功能服务,有没有什么特殊的配置要求是我漏掉的?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.07 11:14:29