为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

qq_花开花谢_0 2021-06-04 14:37:00
在使用 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());    }}
查看完整描述

2 回答

?
明月笑刀无情

TA贡献1828条经验 获得超4个赞

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


查看完整回答
反对 回复 2021-06-10
?
开心每一天1111

TA贡献1836条经验 获得超13个赞

所以我发现我需要


 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");

    }

我没有检查我从我的意图中得到了什么字符串,因此出现了空异常。


查看完整回答
反对 回复 2021-06-10
  • 2 回答
  • 0 关注
  • 124 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信