在推送通知错误“notificationBuilder.setContentText(currentText).setNumber(++numMessages);”中找不到符号
Posted
技术标签:
【中文标题】在推送通知错误“notificationBuilder.setContentText(currentText).setNumber(++numMessages);”中找不到符号【英文标题】:cannot find symbol in push Notification error "notificationBuilder.setContentText(currentText).setNumber(++numMessages);" 【发布时间】:2017-10-06 17:46:30 【问题描述】:下面是我的代码,我正在使用cordova推送通知,我正在尝试合并多个推送通知,但它给了我错误,对于单个通知它的工作,我找不到问题所在,请建议
package org.apache.cordova.firebase;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.text.TextUtils;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import java.util.Map;
import java.util.Random;
private void sendNotification(String id, String title, String messageBody, Map<String, String> data, boolean showNotification)
Bundle bundle = new Bundle();
int notifyID = 1;
for (String key : data.keySet())
bundle.putString(key, data.get(key));
if (showNotification)
Intent intent = new Intent(this, OnNotificationOpenReceiver.class);
intent.putExtras(bundle);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, id.hashCode(), intent,
PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri);
int numMessages = 0;
//This line gives me error:error: cannot find symbol
notificationBuilder.setContentText(currentText).setNumber(++numMessages);
notificationManager.notify(notifyID, notificationBuilder.build());
else
bundle.putBoolean("tap", false);
FirebasePlugin.sendNotification(bundle);
【问题讨论】:
【参考方案1】:看起来 setContextText 方法中使用的 currentText 没有在代码中的任何地方实例化。
【讨论】:
以上是关于在推送通知错误“notificationBuilder.setContentText(currentText).setNumber(++numMessages);”中找不到符号的主要内容,如果未能解决你的问题,请参考以下文章