Java Code Examples for android.app.NotificationChannel#getGroup()

The following examples show how to use android.app.NotificationChannel#getGroup() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RankingHelper.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void createNotificationChannel(String pkg, int uid, NotificationChannel channel,
        boolean fromTargetApp, boolean hasDndAccess) {
    Preconditions.checkNotNull(pkg);
    Preconditions.checkNotNull(channel);
    Preconditions.checkNotNull(channel.getId());
    Preconditions.checkArgument(!TextUtils.isEmpty(channel.getName()));
    Record r = getOrCreateRecord(pkg, uid);
    if (r == null) {
        throw new IllegalArgumentException("Invalid package");
    }
    if (channel.getGroup() != null && !r.groups.containsKey(channel.getGroup())) {
        throw new IllegalArgumentException("NotificationChannelGroup doesn't exist");
    }
    if (NotificationChannel.DEFAULT_CHANNEL_ID.equals(channel.getId())) {
        throw new IllegalArgumentException("Reserved id");
    }
    NotificationChannel existing = r.channels.get(channel.getId());
    // Keep most of the existing settings
    if (existing != null && fromTargetApp) {
        if (existing.isDeleted()) {
            existing.setDeleted(false);

            // log a resurrected channel as if it's new again
            MetricsLogger.action(getChannelLog(channel, pkg).setType(
                    MetricsProto.MetricsEvent.TYPE_OPEN));
        }

        existing.setName(channel.getName().toString());
        existing.setDescription(channel.getDescription());
        existing.setBlockableSystem(channel.isBlockableSystem());
        if (existing.getGroup() == null) {
            existing.setGroup(channel.getGroup());
        }

        // Apps are allowed to downgrade channel importance if the user has not changed any
        // fields on this channel yet.
        if (existing.getUserLockedFields() == 0 &&
                channel.getImportance() < existing.getImportance()) {
            existing.setImportance(channel.getImportance());
        }

        // system apps and dnd access apps can bypass dnd if the user hasn't changed any
        // fields on the channel yet
        if (existing.getUserLockedFields() == 0 && hasDndAccess) {
            boolean bypassDnd = channel.canBypassDnd();
            existing.setBypassDnd(bypassDnd);

            if (bypassDnd != mAreChannelsBypassingDnd) {
                updateChannelsBypassingDnd();
            }
        }

        updateConfig();
        return;
    }
    if (channel.getImportance() < IMPORTANCE_NONE
            || channel.getImportance() > NotificationManager.IMPORTANCE_MAX) {
        throw new IllegalArgumentException("Invalid importance level");
    }

    // Reset fields that apps aren't allowed to set.
    if (fromTargetApp && !hasDndAccess) {
        channel.setBypassDnd(r.priority == Notification.PRIORITY_MAX);
    }
    if (fromTargetApp) {
        channel.setLockscreenVisibility(r.visibility);
    }
    clearLockedFields(channel);
    if (channel.getLockscreenVisibility() == Notification.VISIBILITY_PUBLIC) {
        channel.setLockscreenVisibility(Ranking.VISIBILITY_NO_OVERRIDE);
    }
    if (!r.showBadge) {
        channel.setShowBadge(false);
    }

    r.channels.put(channel.getId(), channel);
    if (channel.canBypassDnd() != mAreChannelsBypassingDnd) {
        updateChannelsBypassingDnd();
    }
    MetricsLogger.action(getChannelLog(channel, pkg).setType(
            MetricsProto.MetricsEvent.TYPE_OPEN));
}
 
Example 2
Source File: RankingHelper.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(String pkg,
        int uid, boolean includeDeleted, boolean includeNonGrouped, boolean includeEmpty) {
    Preconditions.checkNotNull(pkg);
    Map<String, NotificationChannelGroup> groups = new ArrayMap<>();
    Record r = getRecord(pkg, uid);
    if (r == null) {
        return ParceledListSlice.emptyList();
    }
    NotificationChannelGroup nonGrouped = new NotificationChannelGroup(null, null);
    int N = r.channels.size();
    for (int i = 0; i < N; i++) {
        final NotificationChannel nc = r.channels.valueAt(i);
        if (includeDeleted || !nc.isDeleted()) {
            if (nc.getGroup() != null) {
                if (r.groups.get(nc.getGroup()) != null) {
                    NotificationChannelGroup ncg = groups.get(nc.getGroup());
                    if (ncg == null) {
                        ncg = r.groups.get(nc.getGroup()).clone();
                        ncg.setChannels(new ArrayList<>());
                        groups.put(nc.getGroup(), ncg);

                    }
                    ncg.addChannel(nc);
                }
            } else {
                nonGrouped.addChannel(nc);
            }
        }
    }
    if (includeNonGrouped && nonGrouped.getChannels().size() > 0) {
        groups.put(null, nonGrouped);
    }
    if (includeEmpty) {
        for (NotificationChannelGroup group : r.groups.values()) {
            if (!groups.containsKey(group.getId())) {
                groups.put(group.getId(), group);
            }
        }
    }
    return new ParceledListSlice<>(new ArrayList<>(groups.values()));
}
 
Example 3
Source File: NotificationUtils.java    From AcgClub with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.O)
private void createNotificationChannel() {
  //第一个参数:channel_id
  //第二个参数:channel_name
  //第三个参数:设置通知重要性级别
  //注意:该级别必须要在 NotificationChannel 的构造函数中指定,总共要五个级别;
  //范围是从 NotificationManager.IMPORTANCE_NONE(0) ~ NotificationManager.IMPORTANCE_HIGH(4)
  NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME,
      NotificationManager.IMPORTANCE_DEFAULT);
  channel.canBypassDnd();//是否绕过请勿打扰模式
  channel.enableLights(true);//闪光灯
  channel.setLockscreenVisibility(VISIBILITY_SECRET);//锁屏显示通知
  channel.setLightColor(Color.RED);//闪关灯的灯光颜色
  channel.canShowBadge();//桌面launcher的消息角标
  channel.enableVibration(true);//是否允许震动
  channel.getAudioAttributes();//获取系统通知响铃声音的配置
  channel.getGroup();//获取通知取到组
  channel.setBypassDnd(true);//设置可绕过 请勿打扰模式
  channel.setVibrationPattern(new long[]{100, 100, 200});//设置震动模式
  channel.shouldShowLights();//是否会有灯光
  getManager().createNotificationChannel(channel);
}
 
Example 4
Source File: NotificationUtils.java    From YCUpdateApp with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.O)
private void createNotificationChannel() {
    //第一个参数:channel_id
    //第二个参数:channel_name
    //第三个参数:设置通知重要性级别
    //注意:该级别必须要在 NotificationChannel 的构造函数中指定,总共要五个级别;
    //范围是从 NotificationManager.IMPORTANCE_NONE(0) ~ NotificationManager.IMPORTANCE_HIGH(4)
    NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME,
            NotificationManager.IMPORTANCE_LOW);
    channel.canBypassDnd();//是否绕过请勿打扰模式
    channel.enableLights(true);//是否在桌面icon右上角展示小红点
    channel.setLockscreenVisibility(VISIBILITY_SECRET);//锁屏显示通知
    channel.setLightColor(Color.RED);//闪关灯的灯光颜色
    channel.canShowBadge();//桌面launcher的消息角标
    //channel.enableVibration(false);//是否允许震动
    channel.getAudioAttributes();//获取系统通知响铃声音的配置
    channel.getGroup();//获取通知取到组
    channel.setBypassDnd(true);//设置可绕过 请勿打扰模式
    channel.setSound(null, null);
    //channel.setVibrationPattern(new long[]{100, 100, 200});//设置震动模式
    channel.shouldShowLights();//是否会有灯光
    channel.setShowBadge(true); //是否在久按桌面图标时显示此渠道的通知
    getManager().createNotificationChannel(channel);
}
 
Example 5
Source File: NotificationUtils.java    From YCNotification with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.O)
private void createNotificationChannel() {
    //第一个参数:channel_id
    //第二个参数:channel_name
    //第三个参数:设置通知重要性级别
    //注意:该级别必须要在 NotificationChannel 的构造函数中指定,总共要五个级别;
    //范围是从 NotificationManager.IMPORTANCE_NONE(0) ~ NotificationManager.IMPORTANCE_HIGH(4)
    NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME,
            NotificationManager.IMPORTANCE_DEFAULT);
    channel.canBypassDnd();//是否绕过请勿打扰模式
    channel.enableLights(true);//闪光灯
    channel.setLockscreenVisibility(VISIBILITY_SECRET);//锁屏显示通知
    channel.setLightColor(Color.RED);//闪关灯的灯光颜色
    channel.canShowBadge();//桌面launcher的消息角标
    channel.enableVibration(true);//是否允许震动
    channel.getAudioAttributes();//获取系统通知响铃声音的配置
    channel.getGroup();//获取通知取到组
    channel.setBypassDnd(true);//设置可绕过 请勿打扰模式
    channel.setVibrationPattern(new long[]{100, 100, 200});//设置震动模式
    channel.shouldShowLights();//是否会有灯光
    getManager().createNotificationChannel(channel);
}