當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。