gpt4 book ai didi

android - Firebase 云消息系统用户界面已停止

转载 作者:搜寻专家 更新时间:2023-11-01 09:26:31 47 4
gpt4 key购买 nike

当我通过 Firebase 控制台发送消息并且我的应用程序在后台或终止一切正常时,通知显示,但是当我的应用程序在前台然后我发送消息时,我得到

System UI has stopped

我用安卓8.0的模拟器

此外,当出现系统 UI 错误时,我的消息会与我发送到那里的所有内容一起记录下来,日志中只有这个错误,没有任何相关内容。

我的代码在这里:

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)

我真的不知道为什么,但是当我把它改成别的东西时,在我的例子中是drawable icon .setSmallIcon(R.drawable.friend_main_icon)有效,应用程序不再崩溃。

关于android - Firebase 云消息系统用户界面已停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50180254/

47 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com