私のアプリケーションにアンドロイド通知を実装しましたが、実際のメッセージ本文の代わりに番号が表示されている点を除いて正常に動作しています。ここで間違って行くいただきました!ここで私は何を取得しています、アンドロイド通知の代わりに番号を取得
のtehのスクリーンショットがあるこれは私が持っているコード、
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}]
バンドルからタイトルと本文を抽出するにはどうすればよいですか?
ありがとうございました。
'data.getString(" message ")はおそらくその値です。 「バンドルデータ」はどこから来ますか? – CommonsWare
バンドルデータがサーバーから送信されています。これは主に、アプリを開いたまま通知を受け取った場合に発生します。 – Zach