我已經在我的應用程序中實現了android通知,它工作正常,除了它顯示一個數字而不是實際的消息體。下面是我得到的德截屏,獲取數字而不是文本的android通知
這是代碼我有,
public static final int MESSAGE_NOTIFICATION_ID = 435345;
private int MESSAGE_TYPE ;
@Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("message");
String type = data.getString("type");
if(type.equalsIgnoreCase("Load Messages"))
{
MESSAGE_TYPE = Global.NOTIFICATION_LOAD_MESSAGE;
EventBus.getDefault().post(new HandyManEvents.ReloadMessages(true));
}
else
{
MESSAGE_TYPE = Global.NOTIFICATION_LOAD_LIVE_JOBS;
}
createNotification(from, message);
}
// Creates notification based on title and body received
private void createNotification(String title, String body) {
Context context = getBaseContext();
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.putExtra("menuFragment", MESSAGE_TYPE);
PendingIntent pending= PendingIntent.getActivity(context, 0,notificationIntent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title)
.setContentIntent(pending)
.setContentText(body);
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
}
任何線索怎麼回事錯在這裏?
更新 當應用程序在前臺運行時,我看到了這種行爲。這是我從通知中得到的包,
Bundle[{type=Load Messages, notification=Bundle[{e=1, body=You have a new message, icon=app_icon, title=New Message}], collapse_key=com.company.app}]
如何從Bundle中提取標題和正文?
謝謝。
推測「data.getString(」message「)」是該值。 '捆綁數據'來自哪裏? – CommonsWare
捆綁數據來自服務器。這主要發生在我接收到應用程序打開的通知時。 – Zach