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


Java NotificationManager.IMPORTANCE_MAX属性代码示例

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


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

示例1: createNotificationChannel

@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,代码行数:25,代码来源:Background.java

示例2: onMessageReceived

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.e("FCM", "Message data payload: " + remoteMessage.getData());
    }

    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("google.sent_time", remoteMessage.getSentTime());
    intent.putExtra("from", remoteMessage.getFrom());
    intent.putExtra("google.message_id", remoteMessage.getMessageId());
    intent.putExtra("collapse_key", remoteMessage.getCollapseKey());
    for (Map.Entry<String, String> entry : remoteMessage.getData().entrySet()) {
        intent.putExtra(entry.getKey(), entry.getValue());
    }
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification)
            .setColor(Color.parseColor(remoteMessage.getData().get("color")))
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(remoteMessage.getData().get("content")))
            .setContentTitle(remoteMessage.getData().get("title"))
            .setContentText(remoteMessage.getData().get("content"))
            .setTicker(remoteMessage.getData().get("content"))
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        String channelId = "sos_channel_id";
        CharSequence channelName = "SOS Channel";
        int importance = NotificationManager.IMPORTANCE_MAX;

        NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance);
        notificationChannel.enableLights(true);
        notificationChannel.setLightColor(Color.RED);
        notificationChannel.enableVibration(true);
        notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        notificationManager.createNotificationChannel(notificationChannel);
    }

    notificationManager.notify(0, notificationBuilder.build());
}
 
开发者ID:adithya321,项目名称:SOS-The-Healthcare-Companion,代码行数:50,代码来源:MyFirebaseMessagingService.java

示例3: MessagingStyleCommsAppData

private MessagingStyleCommsAppData() {
    // Standard notification values
    // Content for API <24 (M and below) devices
    mContentTitle = "2 Messages w/ Famous McFamously";
    mContentText = "Dude! ... You know I am a Pesce-pescetarian. :P";
    mPriority = NotificationCompat.PRIORITY_HIGH;

    // Style notification values

    // For each message, you need the timestamp, in this case, we are using arbitrary ones.
    long currentTime = System.currentTimeMillis();

    mMessages = new ArrayList<>();
    mMessages.add(
            new MessagingStyle.Message(
                    "What are you doing tonight?", currentTime - 4000, "Famous"));
    mMessages.add(
            new MessagingStyle.Message(
                    "I don't know, dinner maybe?", currentTime - 3000, null));
    mMessages.add(new MessagingStyle.Message("Sounds good.", currentTime - 2000, "Famous"));
    mMessages.add(new MessagingStyle.Message("How about BBQ?", currentTime - 1000, null));
    // Last two are the newest message (2) from friend
    mMessages.add(new MessagingStyle.Message("Hey!", currentTime, "Famous"));
    mMessages.add(
            new MessagingStyle.Message(
                    "You know I am a Pesce-pescetarian. :P", currentTime, "Famous"));

    // String version of the mMessages above
    mFullConversation =
            "Famous: What are you doing tonight?\n\n"
                    + "Me: I don't know, dinner maybe?\n\n"
                    + "Famous: Sounds good.\n\n"
                    + "Me: How about BBQ?\n\n"
                    + "Famous: Hey!\n\n"
                    + "Famous: You know I am a Pesce-pescetarian. :P\n\n";

    mNumberOfNewMessages = 2;

    // Name preferred when replying to chat
    mReplayName = "Me";

    // If the phone is in "Do not disturb mode, the user will still be notified if
    // the user(s) is starred as a favorite.
    mParticipants = new ArrayList<>();
    mParticipants.add("Famous McFamously");

    // Notification channel values (for devices targeting 26 and above):
    mChannelId = "channel_messaging_1";
    // The user-visible name of the channel.
    mChannelName = "Sample Messaging";
    // The user-visible description of the channel.
    mChannelDescription = "Sample Messaging Notifications";
    mChannelImportance = NotificationManager.IMPORTANCE_MAX;
    mChannelEnableVibrate = true;
    mChannelLockscreenVisibility = NotificationCompat.VISIBILITY_PRIVATE;
}
 
开发者ID:googlesamples,项目名称:android-WearAccessibilityApp,代码行数:56,代码来源:MockDatabase.java

示例4: NotificationChannelData

NotificationChannelData(Map<String, Object> channel) {
  id = (String) channel.get("id");
  name = (String) channel.get("name");
  description = (String) channel.get("description");
  groupId = (String) channel.get("groupId");

  importance = (int) CollectionUtil.getOrDefault(channel, "importance",
      importance);
  enableLights = (boolean) CollectionUtil.getOrDefault(channel, "enable_lights", enableLights);
  lightColor = (int) CollectionUtil.getOrDefault(channel, "light_color", lightColor);
  enableVibration = (boolean) CollectionUtil.getOrDefault(channel, "enable_vibration",
      enableVibration);
  lockscreenVisibility = (int) CollectionUtil.getOrDefault(channel, "lockscreen_visibility",
      lockscreenVisibility);
  bypassDnd = (boolean) CollectionUtil.getOrDefault(channel, "bypass_dnd", bypassDnd);
  showBadge = (boolean) CollectionUtil.getOrDefault(channel, "show_badge", showBadge);

  try {
    List<Number> pattern = CollectionUtil.uncheckedCast(
        CollectionUtil.getOrDefault(channel, "vibration_pattern", null));
    if (pattern != null) {
      vibrationPattern = new long[pattern.size()];
      Iterator<Number> iterator = pattern.iterator();
      for (int i = 0; i < vibrationPattern.length; i++) {
        Number next = iterator.next();
        if (next != null) {
          vibrationPattern[i] = next.longValue();
        }
      }
    }
  } catch (Exception e) {
    Log.w("Failed to parse vibration pattern.");
  }

  // Sanity checks.
  if (importance < NotificationManager.IMPORTANCE_NONE &&
      importance > NotificationManager.IMPORTANCE_MAX) {
    importance = NotificationManager.IMPORTANCE_DEFAULT;
  }
  if (lockscreenVisibility < Notification.VISIBILITY_SECRET &&
      lockscreenVisibility > Notification.VISIBILITY_PUBLIC) {
    lockscreenVisibility = Notification.VISIBILITY_PUBLIC;
  }
}
 
开发者ID:Leanplum,项目名称:Leanplum-Android-SDK,代码行数:44,代码来源:LeanplumNotificationChannel.java


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