我能够成功获取firebase令牌,但是当我收到来自服务器的任何通知时,应用程序崩溃并出现以下异常。
java.lang.RuntimeException: Unable to start receiver com.google.firebase.iid.FirebaseInstanceIdReceiver: java.lang.ClassCastException: uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper cannot be cast to android.app.ContextImpl
at android.app.ActivityThread.handleReceiver(ActivityThread.java: 2675)
at android.app.ActivityThread.access$1800(ActivityThread.java: 175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1384)
at android.os.Handler.dispatchMessage(Handler.java: 102)
at android.os.Looper.loop(Looper.java: 146)
at android.app.ActivityThread.main(ActivityThread.java: 5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java: 515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper cannot be cast to android.app.ContextImpl
at android.app.ActivityThread.handleReceiver(ActivityThread.java: 2657)
at android.app.ActivityThread.access$1800(ActivityThread.java: 175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1384)
at android.os.Handler.dispatchMessage(Handler.java: 102)
at android.os.Looper.loop(Looper.java: 146)
at android.app.ActivityThread.main(ActivityThread.java: 5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java: 515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 1099)
at dalvik.system.NativeStart.main(Native Method)
我的app.gradle
有以下依赖关系:
compile 'com.google.firebase:firebase-messaging:10.2.6'
我的project.gradle
有以下依赖关系:
classpath 'com.google.gms:google-services:3.1.0'
FirebaseMessageInstance类:
public class FirebaseMessageInstance extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d("REFRESH_TOKEN",refreshedToken);
}
}
MessagingService类:
public class MessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
}
}