Skip to content
Closed
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions android/app/src/main/res/raw/credits.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Credits

1. `hykenfreak_notification_chime.mp3`
Author: hykenfreak. This work is licensed under the Creative Commons Attribution License.
https://freesound.org/people/hykenfreak/sounds/202029/

2. `rhodesmas_notification_01.mp3`
Author: rhodesmas. This work is licensed under the Creative Commons Attribution License.
Source: https://freesound.org/people/rhodesmas/sounds/342749/

3. `yourfriendjesse_notification_sound.mp3`
Author: YourFriendJesse. This work is licensed under the Creative Commons 0 License.
Source: https://freesound.org/people/YourFriendJesse/sounds/235911/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Icon;
import android.media.AudioAttributes;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.app.Person;
Expand Down Expand Up @@ -134,7 +136,7 @@ protected Notification.Builder getNotificationBuilder(PendingIntent intent) {

Integer notificationId = Integer.parseInt(notId);
notificationColor(notification);
notificationChannel(notification);
notificationChannel(notification, ejson.type);
notificationIcons(notification, bundle);
notificationDismiss(notification, notificationId);

Expand Down Expand Up @@ -208,19 +210,53 @@ private void notificationIcons(Notification.Builder notification, Bundle bundle)
}
}

private void notificationChannel(Notification.Builder notification) {
private void notificationChannel(Notification.Builder notification, String type) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String CHANNEL_ID = "rocketchatrn_channel_01";
String CHANNEL_NAME = "All";

NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
CHANNEL_NAME,
NotificationManager.IMPORTANCE_DEFAULT);
String CHANNEL_ID_ALL = "rocketchatrn_channel_01";
String CHANNEL_NAME_ALL = "All";
String CHANNEL_ID_GROUP = "rocketchatrn_channel_group";
String CHANNEL_NAME_GROUP = "Private Groups";
String CHANNEL_ID_DIRECT = "rocketchatrn_channel_direct";
String CHANNEL_NAME_DIRECT = "Direct Messages";

AudioAttributes att = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build();

// Urgent: Makes a sound and appears as a heads-up notification
// https://developer.android.com/training/notify-user/channels#importance
NotificationChannel generalChannel = new NotificationChannel(CHANNEL_ID_ALL,
CHANNEL_NAME_ALL,
NotificationManager.IMPORTANCE_HIGH);
Uri generalSoundUri = Uri.parse("android.resource://" + mContext.getPackageName() + "/" + R.raw.yourfriendjesse_notification_sound);
generalChannel.setSound(generalSoundUri, att);
NotificationChannel groupChannel = new NotificationChannel(CHANNEL_ID_GROUP,
CHANNEL_NAME_GROUP,
NotificationManager.IMPORTANCE_HIGH);
Uri groupSoundUri = Uri.parse("android.resource://" + mContext.getPackageName() + "/" + R.raw.rhodesmas_notification_01);
groupChannel.setSound(groupSoundUri, att);
NotificationChannel directChannel = new NotificationChannel(CHANNEL_ID_DIRECT,
CHANNEL_NAME_DIRECT,
NotificationManager.IMPORTANCE_HIGH);
Uri directSoundUri = Uri.parse("android.resource://" + mContext.getPackageName() + "/" + R.raw.hykenfreak_notification_chime);
directChannel.setSound(directSoundUri, att);

final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);

notification.setChannelId(CHANNEL_ID);
notificationManager.createNotificationChannel(generalChannel);
notificationManager.createNotificationChannel(groupChannel);
notificationManager.createNotificationChannel(directChannel);

if ("p".equals(type)) {
// type == 'p' (private group)
notification.setChannelId(CHANNEL_ID_GROUP);
} else if ("d".equals(type)) {
// type == 'd' (direct message)
notification.setChannelId(CHANNEL_ID_DIRECT);
} else {
// type == 'c' (public channel) or anything else
notification.setChannelId(CHANNEL_ID_ALL);
}
}
}

Expand Down