当我尝试使用带有通知的Analytics(分析)时,Firebase中没有静态方法zzUr() [英] No static method zzUr() in Firebase when I try to use Analytics with Notifications
问题描述
我只有指南的示例代码才能使用通知和分析。如果我不安装Google Analytics(分析)通知,那么工作正常,但是当我在Gradle中添加分析工具时,当我尝试发送通知时,出现此错误:
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(未知来源)
在com.google.firebase.iid.zzb.onStartCommand(未知源)
在android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3316)
在android.app .ActivityThread.access $ 2200(ActivityThread.java:177)
at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1547)
at android.os.Handler.dispatchMessage(Handler.java: 102)
在android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
在java.lang.reflect.Method.invoke(Native方法)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
我在gradle:
compile'com.google.firebase:firebase-messaging:9.0.2'
co mpile'com.google.firebase:firebase-core:9.2.0'
My MyFirebaseMessagingService: (b)
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ public $ {
// $ T $ {$ b $ TODO(开发者):处理FCM消息这里。
//如果应用程序在前台处理数据和通知消息。
//同样,如果您打算根据收到的FCM
//消息生成您自己的通知,那么这里是应该启动的地方。请参阅下面的sendNotification方法。
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 * /,notificationBuilder.build());
$ / code $
$ p
add
<$ p
firebase-analytics:9.2.0'
编译'com.google.firebase:
compile'com.google.firebase:firebase-messaging:9.0.2'
到THIS(同一版本)
<$ p $ firebase-messaging:9.2.0'
编译'com.google.firebase:
如果这不起作用,请将所有firebase版本设置为9.0.2或9.0.0
I'm starting to use the Firebase Cloud Messaging.
I have only the example code of the guide to use the Notifications and Analytics. If I don't install Analytics notifications works fine, but when I add in gradle the Analytics I have get this error when I try to send a notification:
java.lang.NoSuchMethodError: No static method zzUr()Landroid/content/Intent; in class Lcom/google/firebase/iid/FirebaseInstanceIdInternalReceiver; or its super classes (declaration of 'com.google.firebase.iid.FirebaseInstanceIdInternalReceiver' appears in /data/app/com.myapp.newapp-2/base.apk) at com.google.firebase.messaging.FirebaseMessagingService.zzz(Unknown Source) at com.google.firebase.iid.zzb.onStartCommand(Unknown Source) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3316) at android.app.ActivityThread.access$2200(ActivityThread.java:177) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1547) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5951) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
I have in gradle:
compile 'com.google.firebase:firebase-messaging:9.0.2'
compile 'com.google.firebase:firebase-core:9.2.0'
My 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());
}
Any help will be appreciated!
try this:
add
compile 'com.google.firebase:firebase-analytics:9.2.0'
and change this:
compile 'com.google.firebase:firebase-messaging:9.0.2'
to THIS (same version on all)
compile 'com.google.firebase:firebase-messaging:9.2.0'
if this doesn't work, put all firebase versions to 9.0.2, or 9.0.0
这篇关于当我尝试使用带有通知的Analytics(分析)时,Firebase中没有静态方法zzUr()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!