Example usage for android.provider Settings ACTION_NOTIFICATION_LISTENER_SETTINGS

List of usage examples for android.provider Settings ACTION_NOTIFICATION_LISTENER_SETTINGS

Introduction

In this page you can find the example usage for android.provider Settings ACTION_NOTIFICATION_LISTENER_SETTINGS.

Prototype

String ACTION_NOTIFICATION_LISTENER_SETTINGS

To view the source code for android.provider Settings ACTION_NOTIFICATION_LISTENER_SETTINGS.

Click Source Link

Document

Activity Action: Show Notification listener settings.

Usage

From source file:com.tomer.alwayson.SettingsFragment.java

private boolean checkNotificationsPermission(Context c, boolean prompt) {
    ContentResolver contentResolver = c.getContentResolver();
    String enabledNotificationListeners = Settings.Secure.getString(contentResolver,
            "enabled_notification_listeners");
    String packageName = c.getPackageName();

    // check to see if the enabledNotificationListeners String contains our package name
    if (enabledNotificationListeners == null || !enabledNotificationListeners.contains(packageName)) {
        ((SwitchPreference) findPreference("notifications_alerts")).setChecked(false);
        if (Utils.isAndroidNewerThanL() && prompt) {
            Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);/* w w  w .j  a  v  a 2s .  c o  m*/
            shouldEnableNotificationsAlerts = true;
        } else if (prompt) {
            startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
            shouldEnableNotificationsAlerts = true;
        }
        return false;
    }
    return true;
}