我正在我的应用程序上执行通知,并且正在使用 firestore。snapshotlistener
我的问题是,当检测到数据库中新添加的数据时,我想向用户发送通知,但是当我打开应用程序时,即使我没有添加新数据,它也会立即显示现有通知。我需要一些条件,在这些条件下我只能获取新添加的数据,或者如果我的数据库数据中缺少某些内容,则需要克服此问题。下面是我的数据库结构。
db.collection("Buyers")
.document(userID)
.collection("Notifications")
.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot snapshots, @Nullable FirebaseFirestoreException e) {
if (e != null) {
Log.e(LOG_DB, e.toString());
return;
}
for (DocumentChange dc : snapshots.getDocumentChanges()) {
if (dc.getType() == DocumentChange.Type.ADDED) {
String title = dc.getDocument().getData().get("notificationTitle").toString();
String body = dc.getDocument().getData().get("notificationBody").toString();
//Method to set Notifications
getNotification(title, body);
}
}
}
});
鸿蒙传说
呼唤远方
神不在的星期二
相关分类