Firebase Cloud Messaging を使い始めています。
通知と分析を使用するためのガイドのサンプル コードしかありません。Analytics 通知をインストールしないと問題なく動作しますが、Analytics をグラドルに追加すると、通知を送信しようとすると次のエラーが発生します。
java.lang.NoSuchMethodError: 静的メソッドがありません zzUr()Landroid/content/Intent; クラス内 Lcom/google/firebase/iid/FirebaseInstanceIdInternalReceiver; またはそのスーパー クラス (「com.google.firebase.iid.FirebaseInstanceIdInternalReceiver」の宣言は、/data/app/com.myapp.newapp-2/base.apk に表示されます) com.google.firebase.messaging.FirebaseMessagingService.zzz( android.app.ActivityThread.access$2200(ActivityThread.java:
私はgradleに持っています:
compile 'com.google.firebase:firebase-messaging:9.0.2'
compile 'com.google.firebase:firebase-core:9.2.0'
私の MyFirebaseMessagingService:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO(developer): Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
sendNotification(remoteMessage.getNotification().getBody());
}
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
どんな助けでも大歓迎です!