Application crash upon receiving a notification

妖精的绣舞 提交于 2019-12-10 18:35:36

问题


I'm trying to setup a push notification system, to do that, I'm using Firebase Cloud Messaging with Pusher. I followed this tutorial, in order to implement it.

When setting up FCM, I was able to send notifications from FCM's dashboard. Then when I setup Pusher, upon receiving a notification, my application crashes.

I've checked multiple post on the internet, but I couldn't find any that solved my issue. I've checked multiple times my dependencies in my gradle files.

Here is my 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

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'
}

In order to send a notification, i'm using the curl command, provided by the Pusher website :

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!"}}}'

My application detects the notification, but crash when receiving it, there's the error:

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)

回答1:


I discovered the same exact issue. I changed back to com.google.firebase:firebase-messaging:17.5.0. Problem solved.



来源:https://stackoverflow.com/questions/55667172/application-crash-upon-receiving-a-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!