我正在尝试创建一个推送通知,例如 WhatsApp 或 Gmail,其中用户头像出现在通知中。有没有办法在react-native中做到这一点,特别是使用expo?
这是我的 fcm 有效负载
{
"GCM": "{ \"notification\": { \"title\": \"Sender1\" }, \"text\": \"test message\" } }"
}
Run Code Online (Sandbox Code Playgroud)
这是我从谷歌得到的一个例子,我想实现它。
答案(来源): 用户@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());
Run Code Online (Sandbox Code Playgroud)
设置大图标就可以了。如果您有任何进一步的信息,请在下面评论
如果您使用的是 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
Run Code Online (Sandbox Code Playgroud)
来源:https ://rnfirebase.io/docs/v5.xx/notifications/reference/AndroidNotification#setLargeIcon
| 归档时间: |
|
| 查看次数: |
2583 次 |
| 最近记录: |