Search in sources :

Example 91 with NotificationChannel

use of android.app.NotificationChannel in project Douya by DreaminginCodeZH.

the class MediaNotification method createNotificationChannel.

private void createNotificationChannel() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        return;
    }
    NotificationChannel channel = new NotificationChannel(mChannelId, mService.getString(mChannelNameRes), mChannelImportance);
    channel.setDescription(mService.getString(mChannelDescriptionRes));
    channel.setShowBadge(false);
    getNotificationManager().createNotificationChannel(channel);
}
Also used : NotificationChannel(android.app.NotificationChannel)

Example 92 with NotificationChannel

use of android.app.NotificationChannel in project kcanotify by antest1.

the class KcaService method createServiceChannel.

private void createServiceChannel() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        int priority = IMPORTANCE_DEFAULT;
        if (getBooleanPreferences(getApplicationContext(), PREF_KCA_SET_PRIORITY)) {
            priority = IMPORTANCE_HIGH;
        }
        NotificationChannel channel = new NotificationChannel(getServiceChannelId(), SERVICE_CHANNEL_NAME, priority);
        channel.enableVibration(false);
        channel.setSound(null, null);
        channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
        notifiManager.deleteNotificationChannel(SERVICE_CHANNEL_ID_OLD);
        notifiManager.createNotificationChannel(channel);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel)

Example 93 with NotificationChannel

use of android.app.NotificationChannel in project kcanotify by antest1.

the class KcaAlarmService method createAlarmChannel.

private void createAlarmChannel(String uri) {
    Log.e("KCA-A", "recv: " + uri);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        String soundKind = getStringPreferences(getApplicationContext(), PREF_KCA_NOTI_SOUND_KIND);
        boolean isVibrate = soundKind.equals(getString(R.string.sound_kind_value_mixed)) || soundKind.equals(getString(R.string.sound_kind_value_vibrate));
        notificationManager.deleteNotificationChannel(ALARM_CHANNEL_ID);
        while (!alarmChannelList.isEmpty()) {
            notificationManager.deleteNotificationChannel(alarmChannelList.poll());
        }
        AudioAttributes.Builder attrs = new AudioAttributes.Builder();
        attrs.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION);
        attrs.setUsage(AudioAttributes.USAGE_NOTIFICATION);
        String channel_name = createAlarmId(uri, isVibrate);
        alarmChannelList.add(channel_name);
        NotificationChannel channel = new NotificationChannel(alarmChannelList.peek(), getStringWithLocale(R.string.notification_appinfo_title), NotificationManager.IMPORTANCE_HIGH);
        channel.setSound(Uri.parse(uri), attrs.build());
        channel.enableVibration(isVibrate);
        channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
        notificationManager.createNotificationChannel(channel);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) KcaUtils.createBuilder(com.antest1.kcanotify.KcaUtils.createBuilder) AudioAttributes(android.media.AudioAttributes)

Example 94 with NotificationChannel

use of android.app.NotificationChannel in project quickstart-android by firebase.

the class MyFirebaseMessagingService method sendNotification.

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 */
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, /* Request code */
    intent, PendingIntent.FLAG_ONE_SHOT);
    String channelId = getString(R.string.default_notification_channel_id);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId).setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle(getString(R.string.fcm_message)).setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // Since android Oreo notification channel is needed.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(channelId, "Channel human readable title", NotificationManager.IMPORTANCE_DEFAULT);
        notificationManager.createNotificationChannel(channel);
    }
    notificationManager.notify(0, /* ID of notification */
    notificationBuilder.build());
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) NotificationCompat(androidx.core.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Uri(android.net.Uri)

Example 95 with NotificationChannel

use of android.app.NotificationChannel in project quickstart-android by firebase.

the class MyBaseTaskService method createDefaultChannel.

private void createDefaultChannel() {
    // Since android Oreo notification channel is needed.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        NotificationChannel channel = new NotificationChannel(CHANNEL_ID_DEFAULT, "Default", NotificationManager.IMPORTANCE_DEFAULT);
        nm.createNotificationChannel(channel);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager)

Aggregations

NotificationChannel (android.app.NotificationChannel)762 Test (org.junit.Test)430 NotificationBackend (com.android.settings.notification.NotificationBackend)215 NotificationManager (android.app.NotificationManager)210 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)114 Intent (android.content.Intent)87 Preference (androidx.preference.Preference)76 PendingIntent (android.app.PendingIntent)73 NotificationChannelGroup (android.app.NotificationChannelGroup)54 NotificationCompat (android.support.v4.app.NotificationCompat)45 Notification (android.app.Notification)43 ArrayList (java.util.ArrayList)34 TargetApi (android.annotation.TargetApi)32 AudioAttributes (android.media.AudioAttributes)31 RequiresApi (android.support.annotation.RequiresApi)28 RequiresApi (androidx.annotation.RequiresApi)25 Uri (android.net.Uri)21 RestrictedListPreference (com.android.settings.RestrictedListPreference)20 SuppressLint (android.annotation.SuppressLint)19 ShortcutInfo (android.content.pm.ShortcutInfo)19