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

Android 14 FOREGROUND_SERVICE_SPECIAL_USE权限异常排查求助

Android 14特殊用途前台服务(specialUse)权限异常问题

我已按照Google指南在Android 14中实现了带更新的specialUse类型前台服务,多数设备运行正常,但部分设备触发以下非致命异常:

Non-fatal Exception: java.lang.SecurityException
Starting FGS with type specialUse callerApp=ProcessRecord{a5fde95 20787:com.myapp/u0a432} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_SPECIAL_USE]

触发异常的代码

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
{
  ServiceCompat.startForeground(this, COUNTDOWN_SERVICE_ID, notification, FOREGROUND_SERVICE_TYPE_SPECIAL_USE);
}
else
{
  startForeground(COUNTDOWN_SERVICE_ID, notification);
}

已尝试的处理及问题

此前遇到过三星设备需显式检查服务权限的问题,因此添加了如下权限检查,但并未解决问题:

if (ContextCompat.checkSelfPermission(this, Manifest.permission.FOREGROUND_SERVICE) == PackageManager.PERMISSION_GRANTED)
{
  // 启动前台服务逻辑
}

若尝试检查Manifest.permission.FOREGROUND_SERVICE_SPECIAL_USE权限,在测试的Android 14设备上均返回false。

Manifest配置

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"/>

...
 <service
    android:name=".CountService"
    android:foregroundServiceType="specialUse"
    android:exported="false">
    <property
        android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
        android:value="[Description of why foreground service is needed]" />
    </service>

Google明确说明FOREGROUND_SERVICE_SPECIAL_USE无需运行时检查,请问问题出在哪里?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 16:22:36