在使用 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 回答
![?](http://img1.sycdn.imooc.com/54584d6100015f5802200220-100-100.jpg)
明月笑刀无情
TA贡献1828条经验 获得超4个赞
您删除了错误的大部分重要行。但是,您必须非常仔细地查看它,甚至对其进行解码。据说:在调用“Firebase.....child()”方法时,“ProfileActivity.onCreate()”方法存在问题。使用变量(而不是固定字符串)调用“child()”方法的行很少,因此其中之一(请检查错误日志并找到该“child()”警告的行)是真正的问题。
![?](http://img1.sycdn.imooc.com/5458472300015f4702200220-100-100.jpg)
开心每一天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");
}
我没有检查我从我的意图中得到了什么字符串,因此出现了空异常。
添加回答
举报
0/150
提交
取消