我正在尝试创建推送通知,例如whatsApp或Gmail,其中用户头像出现在通知中。有没有办法在反应原生中做到这一点,特别是使用世博会?
这是我对fcm的有效载荷
{
"GCM": "{ \"notification\": { \"title\": \"Sender1\" }, \"text\": \"test message\" } }"
}
这是我从谷歌那里得到的一个例子。
答案(来源):用户How to set the app icon as the notification icon in the notification drawer的@manikanta
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher))
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
android.app.NotificationManager notificationManager =
(android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
设置大图标就可以了。如果您有任何进一步的信息,请在下方评论
如果您正在使用React Native(react-native-firebase):
const notif = new firebase.notifications.Notification({
show_in_foreground: true,
})
.android.setSmallIcon('@mipmap/ic_notification') // app icon
// source image might be:
// URL
// android resource e.g. @mipmap/ic_launcher
let source_image = "";
notif.android.setLargeIcon(source_image) // user avatar
资料来源:https://rnfirebase.io/docs/v5.x.x/notifications/reference/AndroidNotification#setLargeIcon