Android 获取Firebase通知后出错

Android 获取Firebase通知后出错,android,firebase,push-notification,firebase-cloud-messaging,Android,Firebase,Push Notification,Firebase Cloud Messaging,这是在收到Firebase通知后出现的错误: E/AndroidRuntime: FATAL EXCEPTION: main Process: com.readyscript.dk.storemanagement, PID: 7856 java.lang.NoSuchMethodError: No static method G()Landroid/content/Intent; in class Lcom/google/firebase/iid/FirebaseInstanceIdIn

这是在收到Firebase通知后出现的错误:

E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.readyscript.dk.storemanagement, PID: 7856
  java.lang.NoSuchMethodError: No static method G()Landroid/content/Intent; in class Lcom/google/firebase/iid/FirebaseInstanceIdInternalReceiver; or its super classes (declaration of 'com.google.firebase.iid.FirebaseInstanceIdInternalReceiver' appears in /data/data/com.readyscript.dk.storemanagement/files/instant-run/dex/slice-com.google.firebase-firebase-iid-9.8.0_8d55835917fc52e46aac681088bc7da722cd628c-classes.dex)
      at com.google.firebase.messaging.FirebaseMessagingService.zzae(Unknown Source)
      at com.google.firebase.iid.zzb.onStartCommand(Unknown Source)
      at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3297)
      at android.app.ActivityThread.-wrap21(ActivityThread.java)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1565)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:154)
      at android.app.ActivityThread.main(ActivityThread.java:6077)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
在我可以从Firebase获得通知之前,但当我添加值
数据时,我的应用程序会在收到通知后中断。我搜索了这个错误,但对我的情况没有任何帮助

服务:

public class MyFirebaseMessagingService extends FirebaseMessagingService {

public static final String ORDER_ID = "com.readyscript.dk.storemanagement.order_id";
private static final String TAG = "MyFirebaseMessagingService";

@SuppressLint("LongLogTag")
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.d(TAG, "FROM: " + remoteMessage.getData());

    if (remoteMessage.getData().size() > 0){
        Log.d(TAG, "Message data: " + remoteMessage.getData());
    }
    if (remoteMessage.getNotification() != null){
        Log.d(TAG, "Message title: " + remoteMessage.getNotification().getTitle());
        Log.d(TAG, "Message body: " + remoteMessage.getNotification().getBody());

        String orderId = null;

        for (Map.Entry<String, String> entry : remoteMessage.getData().entrySet()){
            String key = entry.getKey();
            String value = entry.getValue();
            if (key.equals("order_id")){
                orderId = value;
            }
        }

        sendNotification(remoteMessage.getNotification().getTitle() ,remoteMessage.getNotification().getBody(), orderId);
    }
}

private void sendNotification(String title, String body, String orderId) {

    Intent intent = new Intent(this, OrderDetailsActivity.class);
    intent.putExtra(ORDER_ID, orderId);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ico)
            .setContentTitle(title)
            .setContentText(body)
            .setAutoCancel(true)
            .setSound(notificationSound)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());
 }
}
公共类MyFirebaseMessagingService扩展了FirebaseMessagingService{
公共静态最终字符串ORDER_ID=“com.readyscript.dk.storemanagement.ORDER_ID”;
私有静态最终字符串TAG=“MyFirebaseMessagingService”;
@SuppressLint(“LongLogTag”)
@凌驾
收到消息时公共无效(RemoteMessage RemoteMessage){
Log.d(标记“FROM:”+remoteMessage.getData());
如果(remoteMessage.getData().size()>0){
Log.d(标记,“消息数据:”+remoteMessage.getData());
}
if(remoteMessage.getNotification()!=null){
Log.d(标记,“消息标题:”+remoteMessage.getNotification().getTitle());
Log.d(标记,“消息体:”+remoteMessage.getNotification().getBody());
字符串orderId=null;
对于(Map.Entry:remoteMessage.getData().entrySet()){
String key=entry.getKey();
字符串值=entry.getValue();
if(key.equals(“order_id”)){
orderId=值;
}
}
sendNotification(remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody(),orderId);
}
}
私有void sendNotification(字符串标题、字符串正文、字符串orderId){
意向意向=新意向(此,OrderDetailsActivity.class);
intent.putExtra(订单号,订单号);
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP | intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingEvent PendingEvent=PendingEvent.getActivity(this,0,intent,PendingEvent.FLAG_ONE_SHOT);
Uri notificationSound=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_通知);
NotificationCompat.Builder notificationBuilder=新建NotificationCompat.Builder(此)
.setSmallIcon(R.mipmap.ico)
.setContentTitle(标题)
.setContentText(正文)
.setAutoCancel(真)
.setSound(通知声音)
.setContentIntent(挂起内容);
NotificationManager NotificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION\u服务);
notificationManager.notify(0,notificationBuilder.build());
}
}

Intent
是一个Android方法,因此您的类必须扩展
Activity
Fragment
或其子类。

Intent
是一个Android方法,因此您的类必须扩展
Activity
Fragment
,或其子类之一