Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setShowBadge option for created channel #2089

Merged
merged 5 commits into from
Nov 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -269,21 +269,21 @@ public void sendToNotificationCentreWithPicture(Bundle bundle, Bitmap largeIconB
visibility = NotificationCompat.VISIBILITY_PRIVATE;
}
}

String channel_id = bundle.getString("channelId");

if(channel_id == null) {
channel_id = this.config.getNotificationDefaultChannelId();
}

NotificationCompat.Builder notification = new NotificationCompat.Builder(context, channel_id)
.setContentTitle(title)
.setTicker(bundle.getString("ticker"))
.setVisibility(visibility)
.setPriority(priority)
.setAutoCancel(bundle.getBoolean("autoCancel", true))
.setOnlyAlertOnce(bundle.getBoolean("onlyAlertOnce", false));

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // API 24 and higher
// Restore showing timestamp on Android 7+
// Source: https://developer.android.com/reference/android/app/Notification.Builder.html#setShowWhen(boolean)
Expand All @@ -296,7 +296,7 @@ public void sendToNotificationCentreWithPicture(Bundle bundle, Bitmap largeIconB
// Changing Default mode of notification
notification.setDefaults(Notification.DEFAULT_LIGHTS);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { // API 20 and higher
String group = bundle.getString("group");

Expand Down Expand Up @@ -359,7 +359,7 @@ public void sendToNotificationCentreWithPicture(Bundle bundle, Bitmap largeIconB
largeIconBitmap = BitmapFactory.decodeResource(res, largeIconResId);
}
}

if (largeIconBitmap != null){
notification.setLargeIcon(largeIconBitmap);
}
Expand Down Expand Up @@ -469,32 +469,32 @@ public void sendToNotificationCentreWithPicture(Bundle bundle, Bitmap largeIconB

vibratePattern = new long[]{0, vibration};

notification.setVibrate(vibratePattern);
notification.setVibrate(vibratePattern);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Define the shortcutId
String shortcutId = bundle.getString("shortcutId");

if (shortcutId != null) {
notification.setShortcutId(shortcutId);
}

Long timeoutAfter = (long) bundle.getDouble("timeoutAfter");

if (timeoutAfter != null && timeoutAfter >= 0) {
notification.setTimeoutAfter(timeoutAfter);
}
}

Long when = (long) bundle.getDouble("when");

if (when != null && when >= 0) {
notification.setWhen(when);
}

notification.setUsesChronometer(bundle.getBoolean("usesChronometer", false));

notification.setChannelId(channel_id);
notification.setContentIntent(pendingIntent);

Expand Down Expand Up @@ -717,7 +717,7 @@ public void clearDeliveredNotifications(ReadableArray identifiers) {
@RequiresApi(api = Build.VERSION_CODES.M)
public WritableArray getDeliveredNotifications() {
WritableArray result = Arguments.createArray();

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return result;
}
Expand Down Expand Up @@ -819,10 +819,10 @@ private NotificationManager notificationManager() {

public List<String> listChannels() {
List<String> channels = new ArrayList<>();

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
return channels;

NotificationManager manager = notificationManager();

if (manager == null)
Expand All @@ -840,7 +840,7 @@ public List<String> listChannels() {
public boolean channelBlocked(String channel_id) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
return false;

NotificationManager manager = notificationManager();

if (manager == null)
Expand All @@ -857,7 +857,7 @@ public boolean channelBlocked(String channel_id) {
public boolean channelExists(String channel_id) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
return false;

NotificationManager manager = notificationManager();

if (manager == null)
Expand All @@ -871,7 +871,7 @@ public boolean channelExists(String channel_id) {
public void deleteChannel(String channel_id) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
return;

NotificationManager manager = notificationManager();

if (manager == null)
Expand All @@ -880,7 +880,7 @@ public void deleteChannel(String channel_id) {
manager.deleteNotificationChannel(channel_id);
}

private boolean checkOrCreateChannel(NotificationManager manager, String channel_id, String channel_name, String channel_description, Uri soundUri, int importance, long[] vibratePattern) {
private boolean checkOrCreateChannel(NotificationManager manager, String channel_id, String channel_name, String channel_description, Uri soundUri, int importance, long[] vibratePattern, boolean showBadge) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
return false;
if (manager == null)
Expand All @@ -904,6 +904,7 @@ private boolean checkOrCreateChannel(NotificationManager manager, String channel
channel.enableLights(true);
channel.enableVibration(vibratePattern != null);
channel.setVibrationPattern(vibratePattern);
channel.setShowBadge(showBadge);

if (soundUri != null) {
AudioAttributes audioAttributes = new AudioAttributes.Builder()
Expand Down Expand Up @@ -936,14 +937,15 @@ public boolean createChannel(ReadableMap channelInfo) {
int importance = channelInfo.hasKey("importance") ? channelInfo.getInt("importance") : 4;
boolean vibrate = channelInfo.hasKey("vibrate") && channelInfo.getBoolean("vibrate");
long[] vibratePattern = vibrate ? new long[] { 0, DEFAULT_VIBRATION } : null;
boolean showBadge = channelInfo.hasKey("showBadge") ? channelInfo.getBoolean("showBadge") : true;

NotificationManager manager = notificationManager();

Uri soundUri = playSound ? getSoundUri(soundName) : null;

return checkOrCreateChannel(manager, channelId, channelName, channelDescription, soundUri, importance, vibratePattern);
return checkOrCreateChannel(manager, channelId, channelName, channelDescription, soundUri, importance, vibratePattern, showBadge);
}

public boolean isApplicationInForeground() {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
Expand Down