如何使用 FCM 在 android 中配置令牌到令牌通知?
How to configure the token to token notification in android using FCM?
我正在尝试在 android 中使用 FCM 找出用户对用户的通知调用,
我有一个 "subscribeToTopic("TOPIC Name")" 的示例,但除此之外,我无法弄清楚如何使用 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"
}
我正在尝试在 android 中使用 FCM 找出用户对用户的通知调用, 我有一个 "subscribeToTopic("TOPIC Name")" 的示例,但除此之外,我无法弄清楚如何使用 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"
}