错误:类Builder中的构造函数构建器无法应用于给定类型

时间:2018-04-02 10:27:37

标签: android builder build-script

这是我的代码: 在此代码中显示错误

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());
}
}

2 个答案:

答案 0 :(得分:0)

从文档https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html我可以看到new NotificationCompat.Builder作为参数contextstring,您正在提供thisString,在您的情况下,this会引用com.google.firebase.messaging.FirebaseMessagingService而不是context

答案 1 :(得分:0)

使用通知代替 NotificationCompact 例如:

Notification.Builder mBuilder =新的Notification.Builder(this,getString(R.string.default_notification_channel_id))