Search in sources :

Example 46 with AudioAttributes

use of android.media.AudioAttributes in project xDrip by NightscoutFoundation.

the class NotificationChannels method getChan.

@TargetApi(26)
public static NotificationChannel getChan(Notification.Builder wip) {
    final Notification temp = wip.build();
    if (temp.getChannelId() == null)
        return null;
    // create generic audio attributes
    final AudioAttributes generic_audio = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN).build();
    // create notification channel for hashing purposes from the existing notification builder
    NotificationChannel template = new NotificationChannel(temp.getChannelId(), getString(temp.getChannelId()), NotificationManager.IMPORTANCE_DEFAULT);
    // mirror the notification parameters in the channel
    template.setGroup(temp.getChannelId());
    template.setVibrationPattern(temp.vibrate);
    template.setSound(temp.sound, generic_audio);
    template.setLightColor(temp.ledARGB);
    if ((temp.ledOnMS != 0) && (temp.ledOffMS != 0))
        // weird how this doesn't work like vibration pattern
        template.enableLights(true);
    template.setDescription(temp.getChannelId() + " " + wip.hashCode());
    // get a nice string to identify the hash
    final String mhash = my_text_hash(template);
    // create another notification channel using the hash because id is immutable
    final NotificationChannel channel = new NotificationChannel(template.getId() + mhash, getString(temp.getChannelId()) + mhash, NotificationManager.IMPORTANCE_DEFAULT);
    // mirror the settings from the previous channel
    channel.setSound(template.getSound(), generic_audio);
    if (addChannelGroup()) {
        channel.setGroup(template.getGroup());
    } else {
        channel.setGroup(channel.getId());
    }
    channel.setDescription(template.getDescription());
    channel.setVibrationPattern(template.getVibrationPattern());
    template.setLightColor(temp.ledARGB);
    if ((temp.ledOnMS != 0) && (temp.ledOffMS != 0))
        // weird how this doesn't work like vibration pattern
        template.enableLights(true);
    template.setDescription(temp.getChannelId() + " " + wip.hashCode());
    // create a group to hold this channel if one doesn't exist or update text
    getNotifManager().createNotificationChannelGroup(new NotificationChannelGroup(channel.getGroup(), getString(channel.getGroup())));
    // create this channel if it doesn't exist or update text
    getNotifManager().createNotificationChannel(channel);
    return channel;
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) AudioAttributes(android.media.AudioAttributes) Notification(android.app.Notification) TargetApi(android.annotation.TargetApi)

Aggregations

AudioAttributes (android.media.AudioAttributes)46 NotificationChannel (android.app.NotificationChannel)13 Notification (android.app.Notification)11 RemoteException (android.os.RemoteException)10 TargetApi (android.annotation.TargetApi)9 Uri (android.net.Uri)9 NotificationManager (android.app.NotificationManager)6 Test (org.junit.Test)6 Config (org.robolectric.annotation.Config)6 ITransientNotification (android.app.ITransientNotification)5 IRingtonePlayer (android.media.IRingtonePlayer)5 SoundPool (android.media.SoundPool)5 StatusBarNotification (android.service.notification.StatusBarNotification)5 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)5 NotificationChannelGroup (android.app.NotificationChannelGroup)4 PendingIntent (android.app.PendingIntent)3 AudioManager (android.media.AudioManager)3 AudioPlaybackConfiguration (android.media.AudioPlaybackConfiguration)3 RequiresApi (android.support.annotation.RequiresApi)3 Intent (android.content.Intent)2