0
A
回答
0
是的。可以做到这一点。退房参考Firebase Notification Github Repo
推送通知将基于两点
- 发送到特定设备(基于FCM令牌)
- 发送到设备的组被触发(基于订阅的话题)
onMessageReceived(RemoteMessage remoteMessage)
将被称为如果设备接收到的消息
能访问REM OTE消息,并以此为基础进行的需要和要求
动作我尽量保持简单的初步发展
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Do nothing if message is null
if (remoteMessage == null) return;
// Data exists
if (remoteMessage.getData().size() > 0) {
// To show the notification pass the entire remote message as string
sendNotification(remoteMessage.getData().toString());
// if you've JSON string then decode and handle accordingly
// Sample
/**
try {
JSONObject json = new JSONObject(remoteMessage.getData().toString());
sendNotification(JSONObject json); // Need to add method to the class to handle this
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
}
*/
}
/**
* Create and show a simple notification containing the received FCM message.
* @param messageBody FCM message body received.
*/
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
String channelId = getString(R.string.default_notification_channel_id);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_stat_ic_notification)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
}
相关问题
- 1. 发送通知的背景火力地堡的Android
- 2. 火力地堡数据库通知
- 3. 春季背景/火与遗忘处理
- 4. 如何处理背景以及前景的Firebase通知?
- 5. 背景通知
- 6. 背景处理!
- 7. 火力地堡背景和非活动的通知不显示的iOS
- 8. 处理电影背景变化
- 9. 背景PHP函数处理
- 10. 从背景通知
- 11. iPhone背景通知
- 12. 火力地堡通知不会从火力地堡控制台
- 13. 数据从火力
- 14. 邮差 - 火力地堡通知IOS
- 15. 火力地堡推送通知SWIFT 3
- 16. 保存火力地堡通知
- 17. 注册,火力通知应用启动
- 18. 火力地堡通知未在后台
- 19. 火力地堡通知从Android设备
- 20. 火力地堡推送通知仅
- 21. iOS本地通知背景
- 22. 背景通知+ Windows 8
- 23. 火力地堡保存数据时,应用程序是在背景
- 24. 火力地堡推送通知 - 如何出现在通知
- 25. 机器人 - 火力地堡通知推送通知不工作
- 26. 火力地堡通知:状态栏通知被点击
- 27. Android处理程序背景
- 28. Clojure中的背景处理
- 29. 通知点击处理推送通知有效载荷数据
- 30. 通过聚合火力/火力点查询元素将数据推送到Firebase