这里也提出了类似的问题,但没有得到答案。我正在尝试使用 FCM 并使用 github 的官方 Firebase 示例中提到的代码发送设备到设备的通知:
public void sendToToken() throws FirebaseMessagingException {
// [START send_to_token]
// This registration token comes from the client FCM SDKs.
String registrationToken = YOUR_REGISTRATION_TOKEN;
// See documentation on defining a message payload.
Message message = Message.builder()
.putData("score", "850")
.putData("time", "2:45")
.setToken(registrationToken)
.build();
// Send a message to the device corresponding to the provided
// registration token.
String response = FirebaseMessaging.getInstance().send(message);
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);
// [END send_to_token]
}
但是在运行该应用程序时,我收到此错误:
error: incompatible types: Message cannot be converted to RemoteMessage
消息对象的导入错误。导入波纹管消息
import com.google.firebase.messaging.RemoteMessage;
用
RemoteMessage message = new RemoteMessage(bundle);