[FIX] Notification in Android API level less than 24 (#1692)
This commit is contained in:
parent
3683b8936a
commit
e588c1fc08
|
@ -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,8 +189,22 @@ public class CustomPushNotification extends PushNotification {
|
|||
}
|
||||
|
||||
private void notificationStyle(Notification.Builder notification, int notId, Bundle bundle) {
|
||||
List<Bundle> bundles = notificationMessages.get(Integer.toString(notId));
|
||||
|
||||
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");
|
||||
|
||||
messageStyle.addLine(message);
|
||||
}
|
||||
}
|
||||
|
||||
notification.setStyle(messageStyle);
|
||||
} else {
|
||||
Notification.MessagingStyle messageStyle;
|
||||
String title = bundle.getString("title");
|
||||
|
||||
Gson gson = new Gson();
|
||||
Ejson ejson = gson.fromJson(bundle.getString("ejson", "{}"), Ejson.class);
|
||||
|
@ -195,10 +219,9 @@ public class CustomPushNotification extends PushNotification {
|
|||
messageStyle = new Notification.MessagingStyle(sender);
|
||||
}
|
||||
|
||||
String title = bundle.getString("title");
|
||||
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);
|
||||
|
@ -226,6 +249,7 @@ public class CustomPushNotification extends PushNotification {
|
|||
|
||||
notification.setStyle(messageStyle);
|
||||
}
|
||||
}
|
||||
|
||||
private void notificationReply(Notification.Builder notification, int notificationId, Bundle bundle) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
||||
|
|
Loading…
Reference in New Issue