当前位置: 首页>>代码示例>>Java>>正文


Java NotificationChannel.setBypassDnd方法代码示例

本文整理汇总了Java中android.app.NotificationChannel.setBypassDnd方法的典型用法代码示例。如果您正苦于以下问题:Java NotificationChannel.setBypassDnd方法的具体用法?Java NotificationChannel.setBypassDnd怎么用?Java NotificationChannel.setBypassDnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.NotificationChannel的用法示例。


在下文中一共展示了NotificationChannel.setBypassDnd方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createNotificationChannel

import android.app.NotificationChannel; //导入方法依赖的package包/类
@TargetApi(26)
private void createNotificationChannel() {

    notificationChannelClass = new NotificationChannel("class", "Class Notifications", NotificationManager.IMPORTANCE_LOW);
    notificationChannelClass.setDescription("Notifications about classes.");
    notificationChannelClass.enableLights(false);
    notificationChannelClass.enableVibration(false);
    notificationChannelClass.setBypassDnd(false);
    notificationChannelClass.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
    notificationChannelClass.setShowBadge(false);

    notificationManager.createNotificationChannel(notificationChannelClass);

    notificationChannelReminder = new NotificationChannel("reminder", "Reminders", NotificationManager.IMPORTANCE_MAX);
    notificationChannelReminder.setDescription("Notifications about events.");
    notificationChannelReminder.enableLights(true);
    notificationChannelReminder.setLightColor(sharedPreferences.getInt("primary_color", ContextCompat.getColor(this, R.color.teal)));
    notificationChannelReminder.enableVibration(true);
    notificationChannelReminder.setBypassDnd(true);
    notificationChannelReminder.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
    notificationChannelReminder.setShowBadge(true);

    notificationManager.createNotificationChannel(notificationChannelReminder);

}
 
开发者ID:arminghofrani,项目名称:chalkboard,代码行数:26,代码来源:Background.java

示例2: createNotificationChannel

import android.app.NotificationChannel; //导入方法依赖的package包/类
public static String createNotificationChannel(@NonNull final Context context) {
	final NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
	if (notificationManager == null) {
		return "";
	}

	final NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
	channel.setDescription(CHANNEL_DESCRIPTION);
	channel.enableLights(false);
	channel.enableVibration(false);
	channel.setBypassDnd(false);
	channel.setShowBadge(false);
	channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);

	notificationManager.createNotificationChannel(channel);
	return CHANNEL_ID;
}
 
开发者ID:icapps,项目名称:niddler,代码行数:18,代码来源:OreoCompatHelper.java

示例3: createChannel

import android.app.NotificationChannel; //导入方法依赖的package包/类
/**
 * Create notification channel for Android O
 */
@RequiresApi(Build.VERSION_CODES.O)
private void createChannel() {
    final CharSequence name = getString(R.string.channel_name);
    final int importance = NotificationManager.IMPORTANCE_LOW;
    final NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
    channel.setShowBadge(false);
    channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
    channel.enableVibration(false);
    channel.enableLights(false);
    channel.setBypassDnd(false);
    final NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.createNotificationChannel(channel);
}
 
开发者ID:steevp,项目名称:UpdogFarmer,代码行数:17,代码来源:SteamService.java

示例4: createNotificationChannel

import android.app.NotificationChannel; //导入方法依赖的package包/类
/**
 * Create push notification channel with provided id, name and importance of the channel.
 * You can call this method also when you need to update the name or description of a channel, at
 * this case you should use original channel id.
 *
 * @param context The application context.
 * @param channelId The id of the channel.
 * @param channelName The user-visible name of the channel.
 * @param channelImportance The importance of the channel. Use value from 0 to 5. 3 is default.
 * Read more https://developer.android.com/reference/android/app/NotificationManager.html#IMPORTANCE_DEFAULT
 * Once you create a notification channel, only the system can modify its importance.
 * @param channelDescription The user-visible description of the channel.
 * @param groupId The id of push notification channel group.
 * @param enableLights True if lights enable for this channel.
 * @param lightColor Light color for notifications posted to this channel, if the device supports
 * this feature.
 * @param enableVibration True if vibration enable for this channel.
 * @param vibrationPattern Vibration pattern for notifications posted to this channel.
 * @param lockscreenVisibility How to be shown on the lockscreen.
 * @param bypassDnd Whether should notification bypass DND.
 * @param showBadge Whether should notification show badge.
 */
private static void createNotificationChannel(Context context, String channelId, String
    channelName, int channelImportance, String channelDescription, String groupId, boolean
    enableLights, int lightColor, boolean enableVibration, long[] vibrationPattern, int
    lockscreenVisibility, boolean bypassDnd, boolean showBadge) {
  if (context == null || TextUtils.isEmpty(channelId)) {
    return;
  }
  if (BuildUtil.isNotificationChannelSupported(context)) {
    try {
      NotificationManager notificationManager =
          context.getSystemService(NotificationManager.class);
      if (notificationManager == null) {
        Log.e("Notification manager is null");
        return;
      }

      NotificationChannel notificationChannel = new NotificationChannel(channelId,
          channelName, channelImportance);
      if (!TextUtils.isEmpty(channelDescription)) {
        notificationChannel.setDescription(channelDescription);
      }
      if (enableLights) {
        notificationChannel.enableLights(true);
        notificationChannel.setLightColor(lightColor);
      }
      if (enableVibration) {
        notificationChannel.enableVibration(true);
        // Workaround for https://issuetracker.google.com/issues/63427588
        if (vibrationPattern != null && vibrationPattern.length != 0) {
          notificationChannel.setVibrationPattern(vibrationPattern);
        }
      }
      if (!TextUtils.isEmpty(groupId)) {
        notificationChannel.setGroup(groupId);
      }
      notificationChannel.setLockscreenVisibility(lockscreenVisibility);
      notificationChannel.setBypassDnd(bypassDnd);
      notificationChannel.setShowBadge(showBadge);

      notificationManager.createNotificationChannel(notificationChannel);
    } catch (Throwable t) {
      Util.handleException(t);
    }
  }
}
 
开发者ID:Leanplum,项目名称:Leanplum-Android-SDK,代码行数:68,代码来源:LeanplumNotificationChannel.java

示例5: showNotification

import android.app.NotificationChannel; //导入方法依赖的package包/类
@SuppressWarnings({"ConstantConditions", "deprecation"})
public static void showNotification(final Context context, final String[] payload) {
    final NotificationManager manager = context.getSystemService(NotificationManager.class);

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        final NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
                NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
        channel.enableVibration(true);
        channel.enableLights(true);
        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        channel.setBypassDnd(false);
        channel.setShowBadge(true);

        manager.createNotificationChannel(channel);
    }

    final Intent resultIntent = new Intent(context, MainActivity.class);

    resultIntent.putExtra(INTENT_EXTRA_LAUNCH_FROM_NOTIFICATIONS, payload[0]);
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

    final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

    inboxStyle.setBigContentTitle(context.getString(R.string.notification_title_big));

    for (final String title : payload) {
        inboxStyle.addLine(title);
    }

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    builder.setChannelId(NOTIFICATION_CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_rss_feed_white_24dp)
            .setContentTitle(context.getString(R.string.notification_title))
            .setContentText(context.getString(R.string.notification_text))
            .setContentIntent(contentIntent)
            .setWhen(System.currentTimeMillis())
            .setShowWhen(true)
            .setAutoCancel(true)
            .setStyle(inboxStyle);

    manager.notify(NOTIFICATION_ID, builder.build());
}
 
开发者ID:Applications-Development,项目名称:SimpleRssReader,代码行数:47,代码来源:BackgroundService.java


注:本文中的android.app.NotificationChannel.setBypassDnd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。