我的应用程序请求检查用户是否不允许启动前台服务。但是
if (checkCallingOrSelfPermission("android.permission.FOREGROUND_SERVICE") == PackageManager.PERMISSION_GRANTED) {
//always true ??? but the user has not allowed this permission
}
最佳答案
Apps wanting to use foreground services must now request the FOREGROUND_SERVICE permission first. This is a normal permission, so the system automatically grants it to the requesting app. Starting a foreground service without the permission throws a SecurityException.
解决方案是在 AndroidManifest.xml
中添加以下内容:
<manifest ...>
...
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
...
<application ...>
...
</manifest>
关于android - 如何检查用户是否拒绝了 android.permission.FOREGROUND_SERVICE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58693959/