areNotificationsEnabled

areNotificationsEnabled

本文介绍了android NotificationManagerCompat.areNotificationsEnabled无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NotificationManagerCompat.areNotificationsEnabled()如何工作?我已尝试执行以下appPushEnabled = String.valueOf(NotificationManagerCompat.areNotificationsEnabled());但是它给我一个错误吗?

How does NotificationManagerCompat.areNotificationsEnabled() work? I have tried to do the following appPushEnabled = String.valueOf(NotificationManagerCompat.areNotificationsEnabled());however it is giving me an error?

还说它仅在某些设备上有效,我需要尝试一下吗?

Also it says it only works on some devices do I need a try catch on it?

推荐答案

经过几个小时的测试,这是我所发现的.

After testing for few hours, here is what I have found.

在App Gradle文件中,com.android.support:support至少应为24,compileSdkVersion必须为24

In App Gradle file, com.android.support:support should be minimum 24 and compileSdkVersion has to be 24

android {    
    compileSdkVersion 24      
}    
dependencies {
     compile 'com.android.support:support-v4:24.0.0'
}

然后@petey的答案将起作用

And then @petey 's answer will be working

NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context);
boolean areNotificationsEnabled = notificationManagerCompat.areNotificationsEnabled();

这篇关于android NotificationManagerCompat.areNotificationsEnabled无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 08:42