推送通知的 Android checkSelfPermission

标签 android permissions push-notification

我的问题是我不确定使用什么字符串键来检查通知权限。对于关键

"com.google.android.c2dm.permission.RECEIVE"

此代码始终返回 true,即使我从我的 list 中删除了权限:

                int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), "com.google.android.c2dm.permission.RECEIVE");
            if (permissionCheck==PackageManager.PERMISSION_GRANTED) {
                Log.d("granted","TRUE");
            }

我还尝试了其他权限字符串,例如“mypkg.permission.C2D_MESSAGE”。

如果这是因为系统中的通知权限被认为是“正常”而不是“危险”,那么我如何检测用户是否在手机设置中为我的应用禁用了通知(如附图)?

enter image description here

最佳答案

您不需要通知检查权限。

您可以使用 NotificationManagerCompat.areNotificationsEnabled()支持库的方法。 您可以在 API 19+ 上使用它,对于低于此的 API,它始终返回 true

关于推送通知的 Android checkSelfPermission,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38591563/

相关文章:

android - 如何在 google maps API for android 中为自动完成预测添加样式?

mysql - ErrCode 为 "Select Into Outfile with a variable"- 权限困惑

mongodb - 角色在 MongoDB 中是如何工作的?

ios - 使用生产证书创建 p12 证书

访问 adb 时未找到 Android findstr

android - 系统指示器不考虑重力。底部

linux - 这个权限是什么意思?

ios - APNS 与主题一起使用吗?

push-notification - GCM/APNS 如何生成注册 ID

android - 如何避免运行时加载 googlemap api Javascript-phonegap?