我在保存某些obj时遇到问题从FireBase推送通知系统开始使用GSon库创建磁盘。Android:在应用程序未运行或处于后台时将Firebase推送通知保存到磁盘
我想要做什么: 当收到推送通知时,会创建一个obj,并将其添加到容器并保存到磁盘。它将被GUI读取并用于创建类似通知列表的Facebook。 只有如果应用程序未运行或处于后台,托盘中还会显示通知图标。
我已经有: 所有的作品,如果应用程序在前台运行。如果应用程序未运行或处于后台,通知图标出现在托盘上,但不执行保存,并且当我打开应用程序时,GUI中不显示任何内容。
这里是我的onMessageReceived从火力
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
NotificationsContainer notificationsContainer;
// TODO(developer): Handle FCM messages here.
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
PixNotifications.sendNotification(remoteMessage.getNotification().getBody(), remoteMessage.getNotification().getTitle()); //Here the app show the icon in system tray, only if it's running in background.
}
notificationsContainer = Utilities.readNotificationsFromDisk(); //Read actual container from disk
if(notificationsContainer == null){ //No container?
notificationsContainer = new NotificationsContainer(); //Create an empty one
}
try{
Notification notification = new Notification(remoteMessage); //Create a displayable notification
notificationsContainer.pushNotification(notification); //Put it in the container
Utilities.saveNotificationsToDisk(notificationsContainer); //Save container to disk
PixideCore.getInstance().reloadNotificationsContainerContent(); //Reload container in PixideCore
} catch (Exception e){
Log.d(TAG, "Notification save to disk error");
}
}
感谢您的帮助!