尝试在后台/前台运行时应用程序崩溃但适用于其他手机

在使用 android studio 和 firebase 时,我的应用程序(在后台或前台)在点击通知时在 API 26 设备上崩溃。而当我使用 API 23 设备时,当应用程序关闭并单击通知时应用程序崩溃,但当应用程序处于后台/前台时仍可以处理通知。我不明白这个问题,任何帮助表示赞赏。


通知服务


import android.app.NotificationManager;

import android.app.PendingIntent;

import android.content.Intent;

import android.support.v4.app.NotificationCompat;


import com.google.firebase.messaging.RemoteMessage;


public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {



    @Override

    public void onMessageReceived(RemoteMessage remoteMessage) {

        super.onMessageReceived(remoteMessage);


        String notification_title = remoteMessage.getNotification().getTitle();

        String notification_message = remoteMessage.getNotification().getBody();


        String click_action = remoteMessage.getNotification().getClickAction();


        String from_user_id = remoteMessage.getData().get("from_user_id");


        NotificationCompat.Builder mBuilder =

                new NotificationCompat.Builder(FirebaseMessagingService.this, "default")

                        .setSmallIcon(R.mipmap.ic_launcher)

                        .setContentTitle(notification_title)

                        .setContentText(notification_message);



        Intent resultIntent = new Intent(click_action);

        resultIntent.putExtra("user_id", from_user_id);



        PendingIntent resultPendingIntent =

                PendingIntent.getActivity(

                        FirebaseMessagingService.this,

                        0,

                        resultIntent,

                        PendingIntent.FLAG_UPDATE_CURRENT

                );


        mBuilder.setContentIntent(resultPendingIntent);





        int mNotificationId = (int) System.currentTimeMillis();


        NotificationManager mNotifyMgr =

                (NotificationManager) getSystemService(NOTIFICATION_SERVICE);



        mNotifyMgr.notify(mNotificationId, mBuilder.build());



    }

}

http://img1.mukewang.com/60c1c1f100019f9d06310368.jpg

qq_花开花谢_0
浏览 125回答 2
2回答

明月笑刀无情

您删除了错误的大部分重要行。但是,您必须非常仔细地查看它,甚至对其进行解码。据说:在调用“Firebase.....child()”方法时,“ProfileActivity.onCreate()”方法存在问题。使用变量(而不是固定字符串)调用“child()”方法的行很少,因此其中之一(请检查错误日志并找到该“child()”警告的行)是真正的问题。

开心每一天1111

所以我发现我需要 final String user_id;    String data = getIntent().getStringExtra("user_id");    if (data == null) {        user_id = getIntent().getStringExtra("from_user_id");    } else {        user_id = getIntent().getStringExtra("user_id");    }我没有检查我从我的意图中得到了什么字符串,因此出现了空异常。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java