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
相关产品推荐
相关产品推荐

