Ich habe Android-Benachrichtigung in meiner Anwendung implementiert und es funktioniert gut, außer dass es eine Zahl anstelle der tatsächlichen Nachricht Körper zeigt. Hier ist teh Screenshot von dem, was ich bekomme,Nummer anstelle von Text für Android-Benachrichtigung
Dies ist der Code, den ich habe,
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());
}
Jede Ahnung, was falsch geht hier vor?
Aktualisiert Wenn App im Vordergrund ausgeführt wird, sehe ich dieses Verhalten. Dies ist das Bündel, das ich von der Benachrichtigung erhalten habe,
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}]
Wie extrahiert man den Titel und den Körper von Bundle?
Danke.
Vermutlich ist 'data.getString (" message ")' dieser Wert. Woher kommen 'Bündeldaten'? – CommonsWare
Bundle-Daten kommen vom Server. Dies geschieht hauptsächlich, wenn ich Benachrichtigungen mit offener App erhalte. – Zach