以下のステップに従うAWS SNSコンソールからデータを取得するために:FCMにプロジェクトを追加し、AWS SNSのためのレガシーサーバーキーを使用)
1。 )(
String deviceToken = FirebaseInstanceId.getInstance().getToken();
3)アプリケーション
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
sendRegistrationToServer(refreshedToken);
}
private void sendRegistrationToServer(String token) {
// TODO: Implement this method to send token to your app server.
}
}
4)onMessageReceivedをオーバーライドして以下のコードを実装:
2)以下のコードを使用してデバイストークンを取得します通知が受け取られたときのその呼び出し:
public class AppFirebaseMessagingService extends FirebaseMessagingService {
static protected int id = 0;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//remoteMessage.getNotification().getBody()
if (remoteMessage.getData().get("default").length() > 0) {
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri ringNotificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notifyBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("ApplicationName")
.setContentText(remoteMessage.getData().get("default"))
.setAutoCancel(true)
.setSound(ringNotificationSound)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(id++, notifyBuilder.build());
}
}
}
AWSから通知を受け取ると、AWSからのメッセージの読み取りにremoteMessage.getData().get("default")
が使用されます。
ここに同じです。そして、メッセージがどのようにいつどこに落ちているのかを知る場所はありません。クラウドウォッチのレポートには、送信したすべてのメッセージの成功が表示されますが、デバイスに配信されたものはありません。この人には答えがある人がいますか?私はFirebaseがここにあると思う。 –