当我通过Firebase控制台发送消息并且我的应用程序在后台或杀死一切正常时,会显示通知,但是当我的应用程序处于前台然后我发送消息时,我会
我使用带有android 8.0映像的模拟器
此外,当出现系统UI错误时,我的消息会记录下我发送的所有内容,只有这个错误而且日志中没有任何内容。
我的代码在这里:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rent-O-Roof</title>
<style type="text/css">
body{
width: 100%;
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
}
.topnav{
overflow: hidden;
background-color: #333;
}
.topnav a{
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover{
background-color: #ddd;
color: black;
}
.active{
background-color: #4CAF50;
color: white;
}
.topnav .icon{
display: none;
}
@media screen and (max-width: 600px){
.topnav a:not(:first-child) {display: none;}
.topnav a.icon {
float: right;
display: block;
}
}
@media screen and (max-width: 600px){
.topnav.responsive {position: relative;}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a{
float: none;
display: block;
text-align: left;
}
}
/* Style the footer */
.footer {
background-color:#777555 ;
padding: 10px;
text-align: center;
}
</style>
</head>
<body>
<div class="topnav" id="myTopnav">
<a href="#home" class="active">Home</a>
<a href="#aboutus">About US</a>
<a href="#contact">Contact US</a>
<a href="#about">google form</a>
<a href="#about">facebook page</a>
<a href="#about">CUSTOMER REVIEW</a>
<a href="#about">CAREERS</a>
<a href="#about">TERM</a>
<a href="#about">OPTIONS</a>
<a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">☰</a>
</div>
<script>
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
</script>
<div style="overflow: hidden;">
<img src="file:///Users/varunwadhwa/Desktop/Header.png" style="width: 100%; height: auto; overflow: hidden; padding: 0;">
<div style="background-color: red; font-size: 48px;">About Us
</div>
</div>
</body>
</html>
编辑: 这是崩溃后出现在日志中的内容:
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());
}
}
}
答案 0 :(得分:2)
好的,我找到了解决方案。
所以,问题是这行代码.setSmallIcon(R.mipmap.ic_launcher)
我真的不知道为什么,但是当我将其更改为其他内容时,在我的情况下,drawable
图标.setSmallIcon(R.drawable.friend_main_icon)
可以正常运行,应用程序不再崩溃。