我是Android新手,当我尝试使用Firebase发送邮件时,我的Android应用程序崩溃了。 有什么想法吗?
的Manifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".RegistrationIntentService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
RegistrationIntentService.java:
public class RegistrationIntentService extends FirebaseInstanceIdService {
// abbreviated tag name
static final String TAG = "RegIntentService";
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
}
}
MyFirebaseMessagingService:
public class MyFirebaseMessagingService extends FirebaseMessagingService{
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
showNotification(remoteMessage.getData().get("message"));
}
private void showNotification(String message) {
Intent i = new Intent(this, Login.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle("BookStore")
.setContentText(message)
.setSmallIcon(R.drawable.book)
.setContentIntent(pendingIntent);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
}
}
MainActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
FirebaseMessaging.getInstance().subscribeToTopic("test");
FirebaseInstanceId.getInstance().getToken();
}
logcat的:
Process: gamingproject.sellmybooks, PID: 20478
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/gamingproject.sellmybooks-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:3055)
at android.app.ActivityThread.access$2200(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1456)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5536)
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:1397)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192)
07-09 14:14:24.634 970-22768/? E/android.os.Debug: ro.product_ship = true
07-09 14:14:24.634 970-22768/? E/android.os.Debug: ro.debug_level = 0x4f4c
07-09 14:14:24.834 2415-22773/? E/SQLiteLog: (284) automatic index on crash_info_summary(package_name_touched)
07-09 14:14:24.904 2415-22773/? E/SQLiteLog: (284) automatic index on crash_info_summary(package_name_touched)
07-09 14:14:25.244 20342-20342/? E/WidgetProviderAssistiveLight: buildUpdate PORTRAIT
07-09 14:14:27.314 268-268/? E/SMD: DCD OFF
07-09 14:14:29.454 970-997/? E/ActivityManager: checkUser: useridlist=null, currentuser=0
07-09 14:14:29.454 970-997/? E/ActivityManager: checkUser: useridlist=null, currentuser=0
07-09 14:14:29.454 970-997/? E/ActivityManager: checkUser: useridlist=null, currentuser=0
07-09 14:14:29.454 970-997/? E/ActivityManager: checkUser: useridlist=null, currentuser=0
07-09 14:14:29.484 22805-22805/? E/Zygote: v2
07-09 14:14:29.504 22805-22805/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
07-09 14:14:29.704 22805-22805/gamingproject.sellmybooks E/AndroidRuntime: FATAL EXCEPTION: main
Process: gamingproject.sellmybooks, PID: 22805
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/gamingproject.sellmybooks-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:3055)
at android.app.ActivityThread.access$2200(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1456)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5536)
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:1397)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192)
07-09 14:14:29.714 970-22837/? E/android.os.Debug: ro.product_ship = true
07-09 14:14:29.714 970-22837/? E/android.os.Debug: ro.debug_level = 0x4f4c
07-09 14:14:29.794 2415-22838/? E/SQLiteLog: (284) automatic index on crash_info_summary(package_name_touched)
07-09 14:14:29.834 2415-22838/? E/SQLiteLog: (284) automatic index on crash_info_summary(package_name_touched)
07-09 14:14:30.214 970-1256/? E/Watchdog: !@Sync 473
07-09 14:14:30.314 268-268/? E/SMD: DCD OFF
07-09 14:14:33.314 268-268/? E/SMD: DCD OFF
07-09 14:14:36.314 268-268/? E/SMD: DCD OFF
07-09 14:14:39.314 268-268/? E/SMD: DCD OFF
07-09 14:14:42.324 268-268/? E/SMD: DCD OFF
07-09 14:14:45.314 268-268/? E/SMD: DCD OFF
07-09 14:14:48.324 268-268/? E/SMD: DCD OFF
07-09 14:14:51.324 268-268/? E/SMD: DCD OFF
07-09 14:14:54.324 268-268/? E/SMD: DCD OFF
07-09 14:14:56.004 970-1006/? E/PowerManagerService: handleSandman : startDreaming, but isDreaming false
07-09 14:14:56.164 970-1040/? E/lights: write_int failed to open -1
07-09 14:14:56.214 970-1070/? E/native: do suspend true
07-09 14:14:56.344 245-245/? E/qdutils: int qdutils::getHDMINode(): Failed to open fb node 2
07-09 14:14:56.344 245-245/? E/qdutils: int qdutils::getHDMINode(): Failed to find HDMI node
07-09 14:14:56.564 245-578/? E/qdutils: int qdutils::getHDMINode(): Failed to open fb node 2
07-09 14:14:56.564 245-578/? E/qdutils: int qdutils::getHDMINode(): Failed to find HDMI node
07-09 14:14:57.004 1778-1778/? E/LibSecureUISvc: svc_sock_send_message(suisvc): Error sending data, -1 vs 4: Connection refused
07-09 14:14:57.324 268-268/? E/SMD: DCD OFF
07-09 14:15:00.214 970-1256/? E/Watchdog: !@Sync 474
07-09 14:15:00.324 268-268/? E/SMD: DCD OFF
07-09 14:15:01.064 1137-1137/? E/LSO: LSO Service is not yet ready!!!
07-09 14:15:03.324 268-268/? E/SMD: DCD OFF
gradle这个:
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.0.0'
// Dependency for Google Sign-In
compile 'com.google.android.gms:play-services-auth:9.2.0'
compile 'com.google.android.gms:play-services-plus:9.2.0'
compile 'com.google.android.gms:play-services-auth:9.2.0'
//Facebook Login
compile 'com.facebook.android:facebook-android-sdk:4.13.2'
// Dependency for Google Messages
compile 'com.google.firebase:firebase-messaging:9.2.0'
}
apply plugin: 'com.google.gms.google-services'
和
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.google.gms:google-services:3.0.0'
}
}
提前谢谢你。
答案 0 :(得分:2)
我找到了解决方案,我已经在我的gradle中写了这个:
compile 'com.google.firebase:firebase-messaging:9.0.2'
而不是:
compile 'com.google.firebase:firebase-messaging:9.2.0'
答案 1 :(得分:0)
这是前一段时间,但这是解决方案:
在清单中,而不是:
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
使用
<action android:name="com.google.firebase.MESSAGING_EVENT"/>