List of usage examples for android.app NotificationChannel setGroup
public void setGroup(String groupId)
From source file:com.keylesspalace.tusky.util.NotificationHelper.java
public static void createNotificationChannelsForAccount(@NonNull AccountEntity account, @NonNull Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); String[] channelIds = new String[] { CHANNEL_MENTION + account.getIdentifier(), CHANNEL_FOLLOW + account.getIdentifier(), CHANNEL_BOOST + account.getIdentifier(), CHANNEL_FAVOURITE + account.getIdentifier() }; int[] channelNames = { R.string.notification_channel_mention_name, R.string.notification_channel_follow_name, R.string.notification_channel_boost_name, R.string.notification_channel_favourite_name }; int[] channelDescriptions = { R.string.notification_channel_mention_descriptions, R.string.notification_channel_follow_description, R.string.notification_channel_boost_description, R.string.notification_channel_favourite_description }; List<NotificationChannel> channels = new ArrayList<>(4); NotificationChannelGroup channelGroup = new NotificationChannelGroup(account.getIdentifier(), account.getFullName());/*from w w w . j av a 2s .c o m*/ //noinspection ConstantConditions notificationManager.createNotificationChannelGroup(channelGroup); for (int i = 0; i < channelIds.length; i++) { String id = channelIds[i]; String name = context.getString(channelNames[i]); String description = context.getString(channelDescriptions[i]); int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel(id, name, importance); channel.setDescription(description); channel.enableLights(true); channel.setLightColor(0xFF2B90D9); channel.enableVibration(true); channel.setShowBadge(true); channel.setGroup(account.getIdentifier()); channels.add(channel); } //noinspection ConstantConditions notificationManager.createNotificationChannels(channels); } }
From source file:com.ruesga.rview.misc.NotificationsHelper.java
@TargetApi(Build.VERSION_CODES.O) public static void createNotificationChannel(Context context, Account account) { if (AndroidHelper.isApi26OrGreater()) { final String defaultChannelName = context.getString(R.string.notifications_default_channel_name, account.getRepositoryDisplayName(), account.getAccountDisplayName()); final NotificationManager nm = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); nm.createNotificationChannelGroup( new NotificationChannelGroup(account.getAccountHash(), defaultChannelName)); NotificationChannel channel = new NotificationChannel(account.getAccountHash(), defaultChannelName, NotificationManager.IMPORTANCE_DEFAULT); channel.setDescription(context.getString(R.string.notifications_default_channel_description)); channel.enableVibration(true);//from w ww.j a va 2 s .co m channel.enableLights(true); channel.setLightColor(ContextCompat.getColor(context, R.color.primaryDark)); channel.setShowBadge(true); channel.setGroup(account.getAccountHash()); nm.createNotificationChannel(channel); } }
From source file:com.commonsware.android.notify.channel.MainActivity.java
private void initContentChannel() { NotificationChannel channel = new NotificationChannel(CHANNEL_CONTENT, getString(R.string.channel_name_content), NotificationManager.IMPORTANCE_LOW); channel.setGroup(GROUP_UPDATES); mgr.createNotificationChannel(channel); }
From source file:com.commonsware.android.notify.channel.MainActivity.java
private void initBattleChannel() { NotificationChannel channel = new NotificationChannel(CHANNEL_BATTLE, getString(R.string.channel_name_battle), NotificationManager.IMPORTANCE_HIGH); channel.setGroup(GROUP_UPDATES); channel.setShowBadge(true);/*from w w w . jav a2 s . com*/ mgr.createNotificationChannel(channel); }
From source file:com.commonsware.android.notify.channel.MainActivity.java
private void initCoinsChannel() { NotificationChannel channel = new NotificationChannel(CHANNEL_COINS, getString(R.string.channel_name_coins), NotificationManager.IMPORTANCE_DEFAULT); channel.setGroup(GROUP_PROMO); mgr.createNotificationChannel(channel); }
From source file:com.irccloud.android.data.collection.NotificationsList.java
@SuppressLint("NewApi") private android.app.Notification buildNotification(String ticker, int cid, int bid, long[] eids, String title, String text, int count, Intent replyIntent, String network, ArrayList<Notification> messages, NotificationCompat.Action otherAction, Bitmap largeIcon, Bitmap wearBackground) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel c = new NotificationChannel(String.valueOf(bid), title, NotificationManager.IMPORTANCE_HIGH); c.setGroup(String.valueOf(cid)); ((NotificationManager) IRCCloudApplication.getInstance().getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(c); }//from w ww. j a v a 2 s. c o m SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()); int defaults = 0; NotificationCompat.Builder builder = new NotificationCompat.Builder( IRCCloudApplication.getInstance().getApplicationContext(), String.valueOf(bid)) .setContentTitle( title + ((network != null && !network.equals(title)) ? (" (" + network + ")") : "")) .setContentText(Html.fromHtml(text)).setAutoCancel(true).setTicker(ticker) .setWhen(eids[0] / 1000).setSmallIcon(R.drawable.ic_stat_notify).setLargeIcon(largeIcon) .setColor(IRCCloudApplication.getInstance().getApplicationContext().getResources() .getColor(R.color.ic_background)) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setCategory(NotificationCompat.CATEGORY_MESSAGE) .setPriority(hasTouchWiz() ? NotificationCompat.PRIORITY_DEFAULT : NotificationCompat.PRIORITY_HIGH) .setOnlyAlertOnce(false); if (ticker != null && (System.currentTimeMillis() - prefs.getLong("lastNotificationTime", 0)) > 2000) { String ringtone = prefs.getString("notify_ringtone", "android.resource://" + IRCCloudApplication.getInstance().getApplicationContext().getPackageName() + "/" + R.raw.digit); if (ringtone.length() > 0) builder.setSound(Uri.parse(ringtone)); } int led_color = Integer.parseInt(prefs.getString("notify_led_color", "1")); if (led_color == 1) { defaults = android.app.Notification.DEFAULT_LIGHTS; } else if (led_color == 2) { builder.setLights(0xFF0000FF, 500, 500); } if (prefs.getBoolean("notify_vibrate", true) && ticker != null && (System.currentTimeMillis() - prefs.getLong("lastNotificationTime", 0)) > 2000) defaults |= android.app.Notification.DEFAULT_VIBRATE; else builder.setVibrate(new long[] { 0L }); builder.setDefaults(defaults); SharedPreferences.Editor editor = prefs.edit(); editor.putLong("lastNotificationTime", System.currentTimeMillis()); editor.commit(); Intent i = new Intent(); i.setComponent(new ComponentName(IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), "com.irccloud.android.MainActivity")); i.putExtra("bid", bid); i.setData(Uri.parse("bid://" + bid)); Intent dismiss = new Intent(IRCCloudApplication.getInstance().getApplicationContext().getResources() .getString(R.string.DISMISS_NOTIFICATION)); dismiss.setData(Uri.parse("irccloud-dismiss://" + bid)); dismiss.putExtra("bid", bid); dismiss.putExtra("eids", eids); PendingIntent dismissPendingIntent = PendingIntent.getBroadcast( IRCCloudApplication.getInstance().getApplicationContext(), 0, dismiss, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent( PendingIntent.getActivity(IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); builder.setDeleteIntent(dismissPendingIntent); WearableExtender wearableExtender = new WearableExtender(); wearableExtender.setBackground(wearBackground); if (messages != null && messages.size() > 0) { StringBuilder weartext = new StringBuilder(); String servernick = getServerNick(messages.get(0).cid); NotificationCompat.MessagingStyle style = new NotificationCompat.MessagingStyle(servernick); style.setConversationTitle(title + ((network != null) ? (" (" + network + ")") : "")); for (Notification n : messages) { if (n != null && n.message != null && n.message.length() > 0) { if (weartext.length() > 0) weartext.append("<br/>"); if (n.message_type.equals("buffer_me_msg")) { style.addMessage(Html.fromHtml(n.message).toString(), n.eid / 1000, " " + ((n.nick == null) ? servernick : n.nick)); weartext.append("<b> ").append((n.nick == null) ? servernick : n.nick).append("</b> ") .append(n.message); } else { style.addMessage(Html.fromHtml(n.message).toString(), n.eid / 1000, n.nick); weartext.append("<b><").append((n.nick == null) ? servernick : n.nick) .append("></b> ").append(n.message); } } } ArrayList<String> history = new ArrayList<>(messages.size()); for (int j = messages.size() - 1; j >= 0; j--) { Notification n = messages.get(j); if (n != null) { if (n.nick == null) history.add(Html.fromHtml(n.message).toString()); else break; } } builder.setRemoteInputHistory(history.toArray(new String[history.size()])); builder.setStyle(style); if (messages.size() > 1) { wearableExtender.addPage( new NotificationCompat.Builder(IRCCloudApplication.getInstance().getApplicationContext()) .setContentText(Html.fromHtml(weartext.toString())) .extend(new WearableExtender().setStartScrollBottom(true)).build()); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { weartext.setLength(0); int j = 0; for (Notification n : messages) { if (messages.size() - ++j < 3) { if (n != null && n.message != null && n.message.length() > 0) { if (weartext.length() > 0) weartext.append("<br/>"); if (n.message_type.equals("buffer_me_msg")) { weartext.append("<b> ").append((n.nick == null) ? servernick : n.nick) .append("</b> ").append(n.message); } else { weartext.append("<b><").append((n.nick == null) ? servernick : n.nick) .append("></b> ").append(n.message); } } } } RemoteViews bigContentView = new RemoteViews( IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), R.layout.notification_expanded); bigContentView.setTextViewText(R.id.title, title + (!title.equals(network) ? (" (" + network + ")") : "")); bigContentView.setTextViewText(R.id.text, Html.fromHtml(weartext.toString())); bigContentView.setImageViewBitmap(R.id.image, largeIcon); bigContentView.setLong(R.id.time, "setTime", eids[0] / 1000); if (count > 3) { bigContentView.setViewVisibility(R.id.more, View.VISIBLE); bigContentView.setTextViewText(R.id.more, "+" + (count - 3) + " more"); } else { bigContentView.setViewVisibility(R.id.more, View.GONE); } if (replyIntent != null && prefs.getBoolean("notify_quickreply", true)) { bigContentView.setViewVisibility(R.id.actions, View.VISIBLE); bigContentView.setViewVisibility(R.id.action_divider, View.VISIBLE); i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class); i.setData(Uri.parse("irccloud-bid://" + bid)); i.putExtras(replyIntent); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent quickReplyIntent = PendingIntent.getActivity( IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT); bigContentView.setOnClickPendingIntent(R.id.action_reply, quickReplyIntent); } builder.setCustomBigContentView(bigContentView); } } if (replyIntent != null) { PendingIntent replyPendingIntent = PendingIntent.getService( IRCCloudApplication.getInstance().getApplicationContext(), bid + 1, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { builder.addAction(new NotificationCompat.Action.Builder(0, "Reply", replyPendingIntent) .setAllowGeneratedReplies(true) .addRemoteInput( new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build()) .build()); } NotificationCompat.Action.Builder actionBuilder = new NotificationCompat.Action.Builder( R.drawable.ic_wearable_reply, "Reply", replyPendingIntent).setAllowGeneratedReplies(true) .addRemoteInput( new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build()); NotificationCompat.Action.WearableExtender actionExtender = new NotificationCompat.Action.WearableExtender() .setHintLaunchesActivity(true).setHintDisplayActionInline(true); wearableExtender.addAction(actionBuilder.extend(actionExtender).build()); NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( title + ((network != null) ? (" (" + network + ")") : "")) .setReadPendingIntent(dismissPendingIntent).setReplyAction(replyPendingIntent, new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build()); if (messages != null) { for (Notification n : messages) { if (n != null && n.nick != null && n.message != null && n.message.length() > 0) { if (n.buffer_type.equals("conversation")) { if (n.message_type.equals("buffer_me_msg")) unreadConvBuilder .addMessage(" " + n.nick + " " + Html.fromHtml(n.message).toString()); else unreadConvBuilder.addMessage(Html.fromHtml(n.message).toString()); } else { if (n.message_type.equals("buffer_me_msg")) unreadConvBuilder .addMessage(" " + n.nick + " " + Html.fromHtml(n.message).toString()); else unreadConvBuilder .addMessage(n.nick + " said: " + Html.fromHtml(n.message).toString()); } } } } else { unreadConvBuilder.addMessage(text); } unreadConvBuilder.setLatestTimestamp(eids[count - 1] / 1000); builder.extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConvBuilder.build())); } if (replyIntent != null && prefs.getBoolean("notify_quickreply", true) && Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class); i.setData(Uri.parse("irccloud-bid://" + bid)); i.putExtras(replyIntent); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent quickReplyIntent = PendingIntent.getActivity( IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(R.drawable.ic_action_reply, "Quick Reply", quickReplyIntent); } if (otherAction != null) { int drawable = 0; if (otherAction.getIcon() == R.drawable.ic_wearable_add) drawable = R.drawable.ic_action_add; else if (otherAction.getIcon() == R.drawable.ic_wearable_reply) drawable = R.drawable.ic_action_reply; builder.addAction( new NotificationCompat.Action(drawable, otherAction.getTitle(), otherAction.getActionIntent())); wearableExtender.addAction(otherAction); } builder.extend(wearableExtender); return builder.build(); }