这是错误,我收到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 :(得分:0)
Intent
是一种Android方法,因此您的类必须扩展Activity
,Fragment
或其中一个子类。