ここでも同様の質問がありましたが、答えがありませんでした。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);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加