[FIX] Notification in Android API level less than 24 (#1692)

This commit is contained in:
Djorkaeff Alexandre 2020-02-11 12:43:35 -03:00 committed by GitHub
parent 3683b8936a
commit e588c1fc08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 66 additions and 42 deletions

View File

@ -94,8 +94,12 @@ public class CustomPushNotification extends PushNotification {
Bundle bundle = mNotificationProps.asBundle();
String notId = bundle.getString("notId", "1");
String title = bundle.getString("title");
String message = bundle.getString("message");
notification
.setContentTitle(title)
.setContentText(message)
.setContentIntent(intent)
.setPriority(Notification.PRIORITY_HIGH)
.setDefaults(Notification.DEFAULT_ALL)
@ -143,8 +147,14 @@ public class CustomPushNotification extends PushNotification {
int smallIconResId = res.getIdentifier("ic_notification", "mipmap", packageName);
notification
.setSmallIcon(smallIconResId);
Gson gson = new Gson();
Ejson ejson = gson.fromJson(bundle.getString("ejson", "{}"), Ejson.class);
notification.setSmallIcon(smallIconResId);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
notification.setLargeIcon(getAvatar(ejson.getAvatarUri()));
}
}
private void notificationChannel(Notification.Builder notification) {
@ -179,52 +189,66 @@ public class CustomPushNotification extends PushNotification {
}
private void notificationStyle(Notification.Builder notification, int notId, Bundle bundle) {
Notification.MessagingStyle messageStyle;
String title = bundle.getString("title");
Gson gson = new Gson();
Ejson ejson = gson.fromJson(bundle.getString("ejson", "{}"), Ejson.class);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
messageStyle = new Notification.MessagingStyle("");
} else {
Person sender = new Person.Builder()
.setKey("")
.setName("")
.build();
messageStyle = new Notification.MessagingStyle(sender);
}
messageStyle.setConversationTitle(title);
List<Bundle> bundles = notificationMessages.get(Integer.toString(notId));
if (bundles != null) {
for (int i = 0; i < bundles.size(); i++) {
Bundle data = bundles.get(i);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
Notification.InboxStyle messageStyle = new Notification.InboxStyle();
if (bundles != null) {
for (int i = 0; i < bundles.size(); i++) {
Bundle data = bundles.get(i);
String message = data.getString("message");
long timestamp = data.getLong("time");
String message = data.getString("message");
String username = data.getString("username");
String senderId = data.getString("senderId");
String avatarUri = data.getString("avatarUri");
String m = extractMessage(message, ejson);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
messageStyle.addMessage(m, timestamp, username);
} else {
Person sender = new Person.Builder()
.setKey(senderId)
.setName(username)
.setIcon(Icon.createWithBitmap(getAvatar(avatarUri)))
.build();
messageStyle.addMessage(m, timestamp, sender);
messageStyle.addLine(message);
}
}
}
notification.setStyle(messageStyle);
notification.setStyle(messageStyle);
} else {
Notification.MessagingStyle messageStyle;
Gson gson = new Gson();
Ejson ejson = gson.fromJson(bundle.getString("ejson", "{}"), Ejson.class);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
messageStyle = new Notification.MessagingStyle("");
} else {
Person sender = new Person.Builder()
.setKey("")
.setName("")
.build();
messageStyle = new Notification.MessagingStyle(sender);
}
String title = bundle.getString("title");
messageStyle.setConversationTitle(title);
if (bundles != null) {
for (int i = 0; i < bundles.size(); i++) {
Bundle data = bundles.get(i);
long timestamp = data.getLong("time");
String message = data.getString("message");
String username = data.getString("username");
String senderId = data.getString("senderId");
String avatarUri = data.getString("avatarUri");
String m = extractMessage(message, ejson);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
messageStyle.addMessage(m, timestamp, username);
} else {
Person sender = new Person.Builder()
.setKey(senderId)
.setName(username)
.setIcon(Icon.createWithBitmap(getAvatar(avatarUri)))
.build();
messageStyle.addMessage(m, timestamp, sender);
}
}
}
notification.setStyle(messageStyle);
}
}
private void notificationReply(Notification.Builder notification, int notificationId, Bundle bundle) {