当我通过firebase控制台发送消息,而我的应用程序在后台运行或终止所有工作时,会显示通知,但当我的应用程序在前台,然后我发送消息时,我会得到
android - Firebase Cloud Messaging System用户界面已停止-LMLPHP
我在android 8.0映像中使用模拟器
另外,当出现系统用户界面错误时,我的消息会记录我发送到那里的所有内容,只有这个错误,日志中没有任何关于它的内容。
我的代码在这里:

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {

        Log.d("FirebaseMessage", "FROM: " + remoteMessage.getFrom());

        if(remoteMessage.getData().size() > 0) {

            Log.d("FirebaseMessage", "Message Data: " + remoteMessage.getData());

        }

        if(remoteMessage.getNotification() != null) {

            Log.d("Firebae Message", "Message body: " +remoteMessage.getNotification().getBody());

            sendNotification(remoteMessage.getNotification().getBody());

        }

    }

    private void sendNotification(String body) {

        Intent intent = new Intent(this, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);


        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

            String CHANNEL_ID = "test_channel";
            CharSequence name = "testChannel";
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);

            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,CHANNEL_ID)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("[TEST] Message")
                    .setContentText(body)
                    .setAutoCancel(true)
                    .setContentIntent(pendingIntent);

            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

            notificationManager.createNotificationChannel(mChannel);

            notificationManager.notify(0, notificationBuilder.build());

        }

    }

}

编辑:
这就是崩溃后出现在日志中的内容:
05-04 17:42:40.889 7028-7102/com.example.wiktor.notesapptesting D/FirebaseMessage: FROM: 632610386607
05-04 17:42:40.896 7028-7102/com.example.wiktor.notesapptesting D/Firebae Message: Message body: test
05-04 17:42:40.919 7028-7055/com.example.wiktor.notesapptesting D/FA: Logging event (FE): notification_receive(_nr), Bundle[{firebase_event_origin(_o)=fcm, firebase_screen_class(_sc)=PlusUsersMainActivity, firebase_screen_id(_si)=4052769648448254679, message_device_time(_ndt)=0, message_time(_nmt)=1525455768, message_id(_nmid)=3256029686705242789}]
05-04 17:42:40.982 7028-7055/com.example.wiktor.notesapptesting V/FA: Connecting to remote service
05-04 17:42:41.021 7028-7055/com.example.wiktor.notesapptesting D/FA: Logging event (FE): notification_foreground(_nf), Bundle[{firebase_event_origin(_o)=fcm, firebase_screen_class(_sc)=PlusUsersMainActivity, firebase_screen_id(_si)=4052769648448254679, message_device_time(_ndt)=0, message_time(_nmt)=1525455768, message_id(_nmid)=3256029686705242789}]
05-04 17:42:41.081 7028-7055/com.example.wiktor.notesapptesting V/FA: Connection attempt already in progress
05-04 17:42:41.081 7028-7055/com.example.wiktor.notesapptesting D/FA: Connected to remote service
05-04 17:42:41.082 7028-7055/com.example.wiktor.notesapptesting V/FA: Processing queued up service tasks: 2
05-04 17:42:43.142 7028-7033/com.example.wiktor.notesapptesting I/zygote: Do partial code cache collection, code=124KB, data=66KB
    After code cache collection, code=124KB, data=66KB
    Increasing code cache capacity to 512KB
05-04 17:42:46.155 7028-7055/com.example.wiktor.notesapptesting V/FA: Inactivity, disconnecting from the service

最佳答案

好了,伙计们,我找到了解决办法。
所以,问题是这行代码.setSmallIcon(R.mipmap.ic_launcher)
我真的不知道为什么,但当我把它改成其他东西时,在我的情况下,图标可以工作,应用程序不再崩溃。

10-07 23:40