Код: Выделить всё
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//Calling method to generate notification
sendNotification(remoteMessage.getNotification().getTitle().toString(), remoteMessage.getNotification().getBody());
}
//This method is only generating push notification
private void sendNotification(String messageTitle, String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("Title", messageTitle);
intent.putExtra("data", messageBody);
intent.putExtra("KEY", "Notify");
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
numNotifications = numNotifications + 1;
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
inboxStyle.setBigContentTitle(getString(R.string.app_notification)) ;
inboxStyle.setSummaryText(getString(R.string.app_count_notifications1)
+ numNotifications + getString(R.string.app_count_notifications2));
inboxStyle.bigText(messageBody);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.q_me_notify)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setStyle(inboxStyle)
.setGroup(TAG)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
try {
notificationManager.notify(TAG, APPID, notificationBuilder.build());
} catch (Exception e) {
e.printStackTrace();
}
}
Код: Выделить всё
Итак , мои вопросы:
- Как заставить приложение отображать MainActivity на переднем плане, независимо от модели и версии ОС, поэтому что детали уведомления отображаются правильно?
- Когда приложение находится в фоновом режиме/завершено, как я могу передать значения уведомлений (Splash -> LoginActivity -> MainActivity), поэтому что сообщение корректно отображается в MainActivity?
Подробнее здесь: https://stackoverflow.com/questions/550 ... n-activity