我正在使用 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");
}
}
但是,当应用程序位于前台时,我将重新发送作为意向。问题是,当您第一次运行初始化时,它正在创建一个TimeSignOn令牌并登录/创建新会话。由于您在浏览应用程序时已经登录,因此这对我来说不再重要,我只需要向他们发送浏览器类应导航到的新页面,而无需重新启动类。Browser.class
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 运算符.class而不是传递 ,这样我就不需要重新加载整个活动?这导致的最大问题是它将多个浏览器活动堆叠到第一个上。intent.putExtra
有没有更好的方法来检查活动是离线还是只是在后台?以下是我目前检查的方式
守着星空守着你
相关分类