这是我的代码: 在此代码中显示错误
getString(R.string.default_notification_channel_id))
这是完整的代码:
public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
String messageTitle = remoteMessage.getNotification().getTitle();
String messageBody = remoteMessage.getNotification().getBody();
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, getString(R.string.default_notification_channel_id))
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
int mNotificationId = (int) System.currentTimeMillis();
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(mNotificationId,mBuilder.build());
}
}
答案 0 :(得分:0)
从文档https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html我可以看到new NotificationCompat.Builder
作为参数context
和string
,您正在提供this
和String
,在您的情况下,this
会引用com.google.firebase.messaging.FirebaseMessagingService
而不是context
。
答案 1 :(得分:0)
使用通知代替 NotificationCompact 例如:
Notification.Builder mBuilder =新的Notification.Builder(this,getString(R.string.default_notification_channel_id))