Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android的onResume中获取通知的标题和消息_Android_Firebase_Notifications_Android Notifications_Firebase Cloud Messaging - Fatal编程技术网

在android的onResume中获取通知的标题和消息

在android的onResume中获取通知的标题和消息,android,firebase,notifications,android-notifications,firebase-cloud-messaging,Android,Firebase,Notifications,Android Notifications,Firebase Cloud Messaging,我试图在Android中使用通知,但遇到了另一个障碍 在我的舱单上我有 <service android:name=".service.MyFirebaseMessagingService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> &

我试图在Android中使用通知,但遇到了另一个障碍

在我的舱单上我有

<service android:name=".service.MyFirebaseMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>
<service android:name=".service.MyFirebaseInstanceIDService">
    <intent-filter>
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
    </intent-filter>
</service>
到目前为止,应用程序运行时一切正常-MyFirebaseMessagingService接收通知

问题1 我希望每个活动都能处理通知——我的意思是,我基本上需要每个活动都有一个广播接收器。然而,95%的活动将以相同的方式处理通知(将其存储在共享首选项中),但5%的活动需要做一些稍微不同的事情。怎么办

问题2: 如果在我收到通知时应用程序未打开,它将进入系统托盘,当我单击它时,启动/启动程序活动将打开,但我希望它转到其他活动

因此,我在启动/启动程序活动中覆盖onResume,如下所示

protected void onResume() {
    super.onResume();

    Bundle resumingBundle = getIntent().getExtras();
    if(resumingBundle != null)
    {
        Log.d("DEBUG", resumingBundle.getString("message")); // error here
    }

}
错误是

java.lang.RuntimeException: Unable to resume activity {com.werdna.apps.testreceivingnotifs/com.andrewb.testnotifapp.StartingActivity}: java.lang.NullPointerException: println needs a message.

如何从intent访问通知的标题和正文?

问题一:您可以让所有活动扩展BaseActivity,它将包含默认的消息处理,边缘案例活动可以覆盖这一点behaviour@howdoidothis我尝试过这种方法,但基本活动从未接收/处理通知
java.lang.RuntimeException: Unable to resume activity {com.werdna.apps.testreceivingnotifs/com.andrewb.testnotifapp.StartingActivity}: java.lang.NullPointerException: println needs a message.