Я отправляю уведомление Данные с моего сервера на мои устройства с помощью FCM.Когда приложение закрыто или работает в фоновом режиме, я заставляю их перезапустить процесс входа в систему, который является моим Initialize.class
файлом.
Here is the onMessageReceived handler I am currently using.
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.e(TAG, "A notification packet was received from Firebase.");
if (remoteMessage.getData() != null) {
Log.e(TAG, "Notification Type: DATA");
String title = remoteMessage.getData().get("title");
String body = remoteMessage.getData().get("body");
String image = remoteMessage.getData().get("image");
MyNotificationManager.getInstance(getApplicationContext()).displayNotification(title, body, image);
} else if (remoteMessage.getNotification() != null) {
Log.e(TAG, "Notification Type: NOTIFICATION");
String title = remoteMessage.getNotification().getTitle();
String body = remoteMessage.getNotification().getBody();
MyNotificationManager.getInstance(getApplicationContext()).displayNotification(title, body, "logo");
}
}
Когда приложение находится на переднем плане, я пересылаю Browser.class
вместо намерения.Проблема заключается в том, что при первом запуске Initialize он создает токен oneTimeSignOn и регистрирует вас / создает новый сеанс.Поскольку вы уже вошли в систему при просмотре приложения, это больше не важно для меня, и мне нужно просто отправить им новую страницу, на которую должен перейти класс браузера, без перезапуска класса.
void displayNotification(String title, String body, String image) {
.....
Class launchIntent = Browser.class;
if (isAppIsInBackground(context)) {
launchIntent = Initialize.class;
}
Intent intent = new Intent(context, launchIntent);
intent.putExtra("NOTIFICATION_PACKET", "CONTENT");
PendingIntent pendingIntent = PendingIntent.getActivity(mCtx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(pendingIntent);
}
Есть ли способ отправить информацию о полезной нагрузке оператору onResume в моем Browser.class вместо передачи intent.putExtra
, поэтому мне не нужно перезагружать всю активность?Большая проблема, которую это вызывает, заключается в том, что в первый стэк накладывается несколько действий браузера.
Есть ли лучший способ проверить, находится ли действие в автономном режиме или только в фоновом режиме?Вот как я сейчас проверяю
private static boolean isAppIsInBackground(Context context) {
boolean isInBackground = true;
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
for (String activeProcess : processInfo.pkgList) {
if (activeProcess.equals(context.getPackageName())) {
isInBackground = false;
}
}
}
}
return isInBackground;
}