1

Это ошибка, которую я получить после получения уведомления Firebase:Ошибка после получения 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, но когда я добавляю значения data, мое приложение перерыв после уведомления. Я искал эту ошибку, но ничего полезного для моей ситуации.

Услуги:

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()); 
} 
} 

ответ

0

Intent является Android метод, так что ваш класс должен расширять Activity, Fragment или одного из своих детей классов.

Смежные вопросы