Example usage for android.provider Settings ACTION_CHANNEL_NOTIFICATION_SETTINGS

List of usage examples for android.provider Settings ACTION_CHANNEL_NOTIFICATION_SETTINGS

Introduction

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

Prototype

String ACTION_CHANNEL_NOTIFICATION_SETTINGS

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

Click Source Link

Document

Activity Action: Show notification settings for a single NotificationChannel .

Usage

From source file:com.google.android.apps.muzei.notifications.NotificationSettingsDialogFragment.java

/**
 * Show the notification settings. This may come in the form of this dialog or the
 * system notification settings on O+ devices.
 *//*from w  w  w . j av  a  2s. co  m*/
public static void showSettings(Fragment fragment) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        Context context = fragment.getContext();
        // Ensure the notification channel exists
        NewWallpaperNotificationReceiver.createNotificationChannel(context);
        Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
        intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
        // Open the specific channel since we only have one notification channel
        intent.putExtra(Settings.EXTRA_CHANNEL_ID, NewWallpaperNotificationReceiver.NOTIFICATION_CHANNEL);
        context.startActivity(intent);
    } else {
        new NotificationSettingsDialogFragment().show(fragment.getChildFragmentManager(), "notifications");
    }
}

From source file:com.commonsware.android.notify.channel.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.settings) {
        Intent i = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);

        i.putExtra(Settings.EXTRA_CHANNEL_ID, CHANNEL_BATTLE);
        i.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());
        startActivity(i);//from  w w  w. j  a  v a 2s.c o m
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.sxt.chat.activity.NotifycationActivity.java

/**
 * ?app? (???channel)//from w  w  w.  j a  v a2s .  co m
 *
 * @param channel ???
 */
public void goToNotificationSettings(String channel) {
    Intent intent = new Intent();
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        intent.setAction(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
        intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());
        intent.putExtra(Settings.EXTRA_CHANNEL_ID, channel);
    } else {
        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.setData(Uri.parse("package:" + getPackageName()));
    }
    startActivity(intent);
}

From source file:com.google.android.apps.muzei.notifications.NewWallpaperNotificationReceiver.java

/**
 * Create the notification channel for the New Wallpaper notification
 * @return False only in the case where the user had wallpapers disabled in-app, but has not
 * yet seen the 'Review your notification settings' notification
 *///w w  w. j a v  a2 s .  com
@RequiresApi(api = Build.VERSION_CODES.O)
static boolean createNotificationChannel(Context context) {
    NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    // On O+ devices, we want to push users to change the system notification setting
    // but we'll use their current value to set the default importance
    int defaultImportance = sp.getBoolean(PREF_ENABLED, true) ? NotificationManager.IMPORTANCE_MIN
            : NotificationManager.IMPORTANCE_NONE;
    if (sp.contains(PREF_ENABLED)) {
        sp.edit().remove(PREF_ENABLED).apply();
        if (defaultImportance == NotificationManager.IMPORTANCE_NONE) {
            // Check to see if there was already a channel and give users an
            // easy way to review their notification settings if they had
            // previously disabled notifications but have not yet disabled
            // the channel
            NotificationChannel existingChannel = notificationManager
                    .getNotificationChannel(NOTIFICATION_CHANNEL);
            if (existingChannel != null
                    && existingChannel.getImportance() != NotificationManager.IMPORTANCE_NONE) {
                // Construct an Intent to get to the notification settings screen
                Intent settingsIntent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
                settingsIntent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
                settingsIntent.putExtra(Settings.EXTRA_CHANNEL_ID,
                        NewWallpaperNotificationReceiver.NOTIFICATION_CHANNEL);
                // Build the notification
                NotificationCompat.Builder builder = new NotificationCompat.Builder(context,
                        NOTIFICATION_CHANNEL).setSmallIcon(R.drawable.ic_stat_muzei)
                                .setColor(ContextCompat.getColor(context, R.color.notification))
                                .setAutoCancel(true)
                                .setContentTitle(context.getText(R.string.notification_settings_moved_title))
                                .setContentText(context.getText(R.string.notification_settings_moved_text))
                                .setContentIntent(PendingIntent.getActivity(context, 0, settingsIntent,
                                        PendingIntent.FLAG_UPDATE_CURRENT))
                                .setStyle(new NotificationCompat.BigTextStyle()
                                        .bigText(context.getText(R.string.notification_settings_moved_text)));
                notificationManager.notify(1, builder.build());
                return false;
            }
        }
    }
    NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL,
            context.getString(R.string.notification_new_wallpaper_channel_name), defaultImportance);
    channel.setShowBadge(false);
    notificationManager.createNotificationChannel(channel);
    return true;
}