Android 7.0 / API24:如何检查通知访问(Settings.Secure.enabled_notification_listeners)

时间:2016-09-23 07:21:09

标签: android android-notifications android-7.0-nougat

在Android 6.0 / API23及更早版本中,以下内容曾经起作用:

$(function(){
    $("body").on('hover','.fromThisSpan',function () {
            $(this).closest(".highlightThisRow").css("background-color", "#fce2e2");
        },function () {
            $(this).closest(".highlightThisRow").css("background-color", "#ffffff");
        });
});

在Android 7.0中,Nougat / API24似乎不再受支持,因为上面的代码会返回String settingEnabled = android.provider.Settings.Secure.getString(this.getContentResolver(), "enabled_notification_listeners");

实际上这里从未提及:https://developer.android.com/reference/android/provider/Settings.Secure.html

我们如何检查我们的应用是否在Android 7.0 Nougat API24中具有通知访问权限?

编辑:实际上,在您首次获得设置中的访问权限之后,上面的代码会返回正确的状态。但不是安装后的初始请求。

1 个答案:

答案 0 :(得分:4)

使用此:

Set<String> packageNames = NotificationManagerCompat.getEnabledListenerPackages (context);