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

升级到Android 13后NotificationListenerService无法正常工作

Android 10 升级到 Android 13 后 NotificationListenerService 失效的排查思路
  • 重新确认通知访问权限
    Android 12及以上版本,应用跨大版本升级后,之前授予的通知访问权限可能会被重置。哪怕你在Android 10中已经完成授权,升级到13后必须让用户重新开启权限。可以通过以下代码引导用户到系统设置页面:

    Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
    startActivity(intent);
    

    注意要在Activity中启动该Intent,确保用户完成授权操作。

  • 校验Manifest的Service声明
    即便你说配置未修改,仍需确认是否符合Android 13的要求:

    • 必须声明android.permission.BIND_NOTIFICATION_LISTENER_SERVICE权限
    • Intent Filter的action必须是android.service.notification.NotificationListenerService
      标准配置示例:
    <service
        android:name=".YourNotificationListenerService"
        android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
        <intent-filter>
            <action android:name="android.service.notification.NotificationListenerService" />
        </intent-filter>
    </service>
    
  • 检查电池优化限制
    Android 12+对后台服务的管控更严格,若应用被纳入电池优化范围,NotificationListenerService可能无法正常启动。可以引导用户关闭对应应用的电池优化:

    Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
    startActivity(intent);
    
  • 添加日志验证服务启动状态
    在Service的onCreate、onListenerConnected方法中添加日志输出,比如:

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d("NotificationService", "onCreate 已执行");
    }
    
    @Override
    public void onListenerConnected() {
        super.onListenerConnected();
        Log.d("NotificationService", "服务已连接");
    }
    

    通过日志确认服务是否真的未被调用,避免误判。

  • 排查目标SDK版本影响
    若升级后将targetSdkVersion设为33(Android 13),系统对NotificationListenerService的启动逻辑会更严格,必须确保用户完成权限授权后,系统才会绑定服务。

  • 清除应用缓存与数据
    尝试清除应用的缓存和数据,重新安装应用后再次授权通知访问权限,排除缓存异常导致的服务无法启动问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 09:42:33