android.app.Notification#getChannelId ( )源码实例Demo

下面列出了android.app.Notification#getChannelId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: NotificationRecord.java
/**
 * Collect all {@link Uri} that should have permission granted to whoever
 * will be rendering it.
 */
protected void calculateGrantableUris() {
    final Notification notification = getNotification();
    notification.visitUris((uri) -> {
        visitGrantableUri(uri, false);
    });

    if (notification.getChannelId() != null) {
        NotificationChannel channel = getChannel();
        if (channel != null) {
            visitGrantableUri(channel.getSound(), (channel.getUserLockedFields()
                    & NotificationChannel.USER_LOCKED_SOUND) != 0);
        }
    }
}
 
源代码2 项目: xDrip   文件: NotificationChannels.java
@TargetApi(26)
public static NotificationChannel getChan(NotificationCompat.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(wip.mNotification.vibrate);
    template.setSound(wip.mNotification.sound, generic_audio);
    template.setLightColor(wip.mNotification.ledARGB);
    if ((wip.mNotification.ledOnMS != 0) && (wip.mNotification.ledOffMS != 0))
        template.enableLights(true); // weird how this doesn't work like vibration pattern
    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(wip.mNotification.ledARGB);
    if ((wip.mNotification.ledOnMS != 0) && (wip.mNotification.ledOffMS != 0))
        template.enableLights(true); // weird how this doesn't work like vibration pattern
    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;
}
 
源代码3 项目: xDrip   文件: NotificationChannels.java
@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))
        template.enableLights(true); // weird how this doesn't work like vibration pattern
    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))
        template.enableLights(true); // weird how this doesn't work like vibration pattern
    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;
}
 
源代码4 项目: xDrip-plus   文件: NotificationChannels.java
@TargetApi(26)
public static NotificationChannel getChan(NotificationCompat.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(wip.mNotification.vibrate);
    template.setSound(wip.mNotification.sound, generic_audio);
    template.setLightColor(wip.mNotification.ledARGB);
    if ((wip.mNotification.ledOnMS != 0) && (wip.mNotification.ledOffMS != 0))
        template.enableLights(true); // weird how this doesn't work like vibration pattern
    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(wip.mNotification.ledARGB);
    if ((wip.mNotification.ledOnMS != 0) && (wip.mNotification.ledOffMS != 0))
        template.enableLights(true); // weird how this doesn't work like vibration pattern
    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;
}
 
源代码5 项目: xDrip-plus   文件: NotificationChannels.java
@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))
        template.enableLights(true); // weird how this doesn't work like vibration pattern
    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))
        template.enableLights(true); // weird how this doesn't work like vibration pattern
    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;
}