如何从Android客户端使用FCM发送上游消息? [英] How to send upstream messages with FCM from android client?
问题描述
我们正在使用GoogleCloudMessaging.getInstance(context).send(context.getString(R.string.gcm_defaultSenderId) + "@gcm.googleapis.com", mId, mBundle);
发送上游消息,但是由于我试图移植新的fcm
概念,因此我也需要进行更改,但找不到任何文档.
We were using GoogleCloudMessaging.getInstance(context).send(context.getString(R.string.gcm_defaultSenderId) + "@gcm.googleapis.com", mId, mBundle);
to send upstream messages, but since I was trying to migrate new fcm
concept, I need to change that too, but could not find any documentation yet.
我最好的猜测是使用:
RemoteMessage message = new RemoteMessage.Builder(<?>).setMessageId(mId).setData ...
FirebaseMessaging.getInstance().send(message);
但是,构建器将其作为参数是什么?再一次,找不到api ...
but then what is it the Builder takes as a parameter? Yet again, could not find api...
如此简单地作为标题说明,如何使用新的fcm
概念发送上游消息?
So simply as title states, how to send upstream messages using new fcm
concept?
推荐答案
嗯,我的回答很快.保留问题和答案以供将来参考.我在 https://firebase.google.com上找到了答案/docs/cloud-messaging/android/upstream#sample-send
Well, my answer comes fast. Keeping question and answer for future reference. I have found the answer on https://firebase.google.com/docs/cloud-messaging/android/upstream#sample-send
感谢Google巧妙地排除搜索结果In order to show you the most relevant results, we have omitted some entries very similar to the 2 already displayed.
If you like, you can repeat the search with the omitted results included.
thanks to google's smart exclusion to search results In order to show you the most relevant results, we have omitted some entries very similar to the 2 already displayed.
If you like, you can repeat the search with the omitted results included.
新API如下:
FirebaseMessaging fm = FirebaseMessaging.getInstance();
fm.send(new RemoteMessage.Builder(SENDER_ID + "@gcm.googleapis.com")
.setMessageId(Integer.toString(msgId.incrementAndGet()))
.addData("my_message", "Hello World")
.addData("my_action","SAY_HELLO")
.build());
这篇关于如何从Android客户端使用FCM发送上游消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!