How to send upstream messages with FCM from android client?

前端 未结 2 1080
误落风尘
误落风尘 2021-02-10 00:19

We were using GoogleCloudMessaging.getInstance(context).send(context.getString(R.string.gcm_defaultSenderId) + \"@gcm.googleapis.com\", mId, mBundle); to send upstr

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-10 00:41

    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

    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.

    new API would be like:

    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());
    

提交回复
热议问题