收到通知后应用程序崩溃 [英] Application crash upon receiving a notification

查看:99
本文介绍了收到通知后应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置推送通知系统,为此,我正在将Firebase Cloud Messaging与Pusher一起使用.为了实现它,我遵循了本教程. /p>

设置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)

解决方案

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

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)

解决方案

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

这篇关于收到通知后应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆