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

The following examples show how to use android.app.NotificationChannel#shouldShowLights() . 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
@VisibleForTesting
void lockFieldsForUpdate(NotificationChannel original, NotificationChannel update) {
    if (original.canBypassDnd() != update.canBypassDnd()) {
        update.lockFields(NotificationChannel.USER_LOCKED_PRIORITY);
    }
    if (original.getLockscreenVisibility() != update.getLockscreenVisibility()) {
        update.lockFields(NotificationChannel.USER_LOCKED_VISIBILITY);
    }
    if (original.getImportance() != update.getImportance()) {
        update.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
    }
    if (original.shouldShowLights() != update.shouldShowLights()
            || original.getLightColor() != update.getLightColor()) {
        update.lockFields(NotificationChannel.USER_LOCKED_LIGHTS);
    }
    if (!Objects.equals(original.getSound(), update.getSound())) {
        update.lockFields(NotificationChannel.USER_LOCKED_SOUND);
    }
    if (!Arrays.equals(original.getVibrationPattern(), update.getVibrationPattern())
            || original.shouldVibrate() != update.shouldVibrate()) {
        update.lockFields(NotificationChannel.USER_LOCKED_VIBRATION);
    }
    if (original.canShowBadge() != update.canShowBadge()) {
        update.lockFields(NotificationChannel.USER_LOCKED_SHOW_BADGE);
    }
}
 
Example 2
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 3
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 4
Source File: EditNotificationSettingsActivity.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
private void loadNotificationRuleSettings() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ||
            mEditingRule == null || mEditingRule.settings == null ||
            mEditingRule.settings.notificationChannelId == null)
        return;
    android.app.NotificationManager mgr = (android.app.NotificationManager)
            getSystemService(NOTIFICATION_SERVICE);
    NotificationChannel channel =
            mgr.getNotificationChannel(mEditingRule.settings.notificationChannelId);

    mEditingRule.settings.soundEnabled = channel.getSound() != null;
    mEditingRule.settings.soundUri = null;
    if (channel.getSound() != null && !channel.getSound().equals(
            RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)))
        mEditingRule.settings.soundUri = channel.getSound().toString();

    mEditingRule.settings.vibrationEnabled = channel.shouldVibrate();
    if (channel.shouldVibrate())
        mEditingRule.settings.vibrationDuration = channel.getVibrationPattern() == null ||
                channel.getVibrationPattern().length != 2
                ? 0 : (int) channel.getVibrationPattern()[1];

    mEditingRule.settings.lightEnabled = channel.shouldShowLights();
    if (channel.shouldShowLights())
        mEditingRule.settings.light = channel.getLightColor();
}
 
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);
}
 
Example 6
Source File: EditNotificationSettingsActivity.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("DoubleNegation")
private boolean hasNotificationRuleChanges() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ||
            mEditingRule == null || mEditingRule.settings.notificationChannelId == null)
        return false;
    android.app.NotificationManager mgr = (android.app.NotificationManager)
            getSystemService(NOTIFICATION_SERVICE);
    NotificationChannel channel =
            mgr.getNotificationChannel(mEditingRule.settings.notificationChannelId);

    Uri soundUri = mSoundEntry.getValue();
    if (channel.getSound() != soundUri &&
            (channel.getSound() == null || !channel.getSound().equals(soundUri)))
        return true;

    int vibrationDuration = mVibrationOptions[mVibrationEntry.getSelectedOption()];
    if (channel.shouldVibrate() != (vibrationDuration != 0))
        return true;
    if (channel.shouldVibrate()) {
        int channelVibrationDuration = channel.getVibrationPattern() == null ||
                channel.getVibrationPattern().length != 2
                ? -1 : (int) channel.getVibrationPattern()[1];
        if (channelVibrationDuration != vibrationDuration)
            return true;
    }

    if (channel.shouldShowLights() != (mColorEntry.getSelectedColorIndex() != 0))
        return true;
    //noinspection RedundantIfStatement
    if (channel.shouldShowLights() && channel.getLightColor() !=
            (mColorEntry.getSelectedColorIndex() == -1 ? 0 : mColorEntry.getSelectedColor()))
        return true;

    return false;
}