【问题标题】:Application crash upon receiving a notification收到通知后应用程序崩溃
【发布时间】:2019-09-04 03:16:25
【问题描述】:

我正在尝试设置一个推送通知系统,为此,我正在使用 Firebase Cloud Messaging 和 Pusher。为了实现它,我关注了this tutorial

在设置 FCM 时,我能够从 FCM 的仪表板发送通知。 然后当我设置 Pusher 时,收到通知后,我的应用程序崩溃了。

我查看了互联网上的多个帖子,但找不到任何可以解决我的问题的帖子。我在我的 gradle 文件中多次检查了我的依赖项。

这是我的 MainActivity.java:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.pusher.pushnotifications.PushNotifications;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        PushNotifications.start(getApplicationContext(), "9e3bfbb7-a6b0-4bcf-aa74-47b4b04fa530");
        PushNotifications.addDeviceInterest("hello");
    }
}

build.gradle (Module:app) - 依赖项

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-messaging:17.6.0'
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.google.firebase:firebase-auth:16.2.1'
    implementation 'com.pusher:push-notifications-android:1.4.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

为了发送通知,我使用了 Pusher 网站提供的 curl 命令:

curl -H "Content-Type: application/json"      -H "Authorization: Bearer 99E1F894C23ECD14DE98003053B3AFC1D3A4335C97C0D1DF5E1105C719979CA3"      -X POST "https://9e3bfbb7-a6b0-4bcf-aa74-47b4b04fa530.pushnotifications.pusher.com/publish_api/v1/instances/9e3bfbb7-a6b0-4bcf-aa74-47b4b04fa530/publishes"      -d '{"interests":["hello"],"fcm":{"notification":{"title":"Hello","body":"Hello, world!"}}}'

我的应用程序检测到通知,但收到通知时崩溃,出现错误:

I/FCMMessageReceiver: Got a valid pusher message.
E/AndroidRuntime: FATAL EXCEPTION: Firebase-WrappedFirebaseMessagingService
    Process: com.example.fcmapp, PID: 10924
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
        at android.content.ContextWrapper.getPackageName(ContextWrapper.java:142)
        at com.google.firebase.messaging.zzb.<init>(Unknown Source:5)
        at com.google.firebase.messaging.FirebaseMessagingService.zzd(Unknown Source:58)
        at com.google.firebase.iid.zzb.run(Unknown Source:2)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source:6)
        at java.lang.Thread.run(Thread.java:764)

【问题讨论】:

    标签: android django firebase-cloud-messaging pusher


    【解决方案1】:

    我发现了同样的问题。我改回com.google.firebase:firebase-messaging:17.5.0。问题解决了。

    【讨论】:

    • 您好,在“com.google.firebase:firebase-messaging:20.0.0”中遇到问题,计划降级其版本。到目前为止,您在 17.5.0 中遇到过什么问题吗??
    • 和是否像 20.0.0 一样默认支持通知图像?
    • 这对我有用,我的应用不再崩溃,但我没有收到通知。
    猜你喜欢
    • 2021-01-19
    • 2014-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多