如何使用FCM在安卓中配置令牌到令牌通知?



我正在尝试使用安卓中的FCM找出用户对用户的通知调用, 我有一个"订阅主题("主题名称"("的示例,但取而代之的是,我无法弄清楚如何使用 FCM 中用户的令牌 ID 将用户应用于用户通知。 我指的是本教程 https://blog.usejournal.com/send-device-to-device-push-notifications-without-server-side-code-238611c143

请协助,提前感谢

btnSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TOPIC = "/topics/userABC"; //topic must match with what the receiver subscribed to
NOTIFICATION_TITLE = edtTitle.getText().toString();
NOTIFICATION_MESSAGE = edtMessage.getText().toString();
JSONObject notification = new JSONObject();
JSONObject notifcationBody = new JSONObject();
try {
notifcationBody.put("title", NOTIFICATION_TITLE);
notifcationBody.put("message", NOTIFICATION_MESSAGE);
notification.put("to", TOPIC);
notification.put("data", notifcationBody);
} catch (JSONException e) {
Log.e(TAG, "onCreate: " + e.getMessage() );
}
sendNotification(notification);
}
});
btnSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TOPIC = "/topics/userABC"; //topic must match with what the receiver subscribed to
NOTIFICATION_TITLE = edtTitle.getText().toString();
NOTIFICATION_MESSAGE = edtMessage.getText().toString();
JSONObject notification = new JSONObject();
JSONObject notifcationBody = new JSONObject();
try {
notifcationBody.put("title", NOTIFICATION_TITLE);
notifcationBody.put("message", NOTIFICATION_MESSAGE);
notification.put("to", TOPIC);
notification.put("data", notifcationBody);
} catch (JSONException e) {
Log.e(TAG, "onCreate: " + e.getMessage() );
}
sendNotification(notification);
}
});

使用这种 JSON 格式将通知发送到特定设备。

{ "notification": {
"title": "Title Message",
"text": "Message here"
},
"to" : "YOUR_TARGET_device_token_id"
}

最新更新