@@ -54,6 +54,7 @@ Map<String, Object> listenToDocument() throws Exception {
54
54
final SettableApiFuture <Map <String , Object >> future = SettableApiFuture .create ();
55
55
56
56
// [START listen_to_document]
57
+ // [START firestore_listen_document]
57
58
DocumentReference docRef = db .collection ("cities" ).document ("SF" );
58
59
docRef .addSnapshotListener (new EventListener <DocumentSnapshot >() {
59
60
@ Override
@@ -76,6 +77,7 @@ public void onEvent(@Nullable DocumentSnapshot snapshot,
76
77
// [END_EXCLUDE]
77
78
}
78
79
});
80
+ // [END firestore_listen_document]
79
81
// [END listen_to_document]
80
82
81
83
return future .get (TIMEOUT_SECONDS , TimeUnit .SECONDS );
@@ -88,6 +90,7 @@ List<String> listenForMultiple() throws Exception {
88
90
final SettableApiFuture <List <String >> future = SettableApiFuture .create ();
89
91
90
92
// [START listen_to_multiple]
93
+ // [START firestore_listen_query_snapshots]
91
94
db .collection ("cities" )
92
95
.whereEqualTo ("state" , "CA" )
93
96
.addSnapshotListener (new EventListener <QuerySnapshot >() {
@@ -113,6 +116,7 @@ public void onEvent(@Nullable QuerySnapshot snapshots,
113
116
// [END_EXCLUDE]
114
117
}
115
118
});
119
+ // [END firestore_listen_query_snapshots]
116
120
// [END listen_to_multiple]
117
121
118
122
return future .get (TIMEOUT_SECONDS , TimeUnit .SECONDS );
@@ -125,6 +129,7 @@ List<DocumentChange> listenForChanges() throws Exception {
125
129
SettableApiFuture <List <DocumentChange >> future = SettableApiFuture .create ();
126
130
127
131
// [START listen_for_changes]
132
+ // [START firestore_listen_query_changes]
128
133
db .collection ("cities" )
129
134
.whereEqualTo ("state" , "CA" )
130
135
.addSnapshotListener (new EventListener <QuerySnapshot >() {
@@ -158,6 +163,7 @@ public void onEvent(@Nullable QuerySnapshot snapshots,
158
163
// [END_EXCLUDE]
159
164
}
160
165
});
166
+ // [END firestore_listen_query_changes]
161
167
// [END listen_for_changes]
162
168
163
169
return future .get (TIMEOUT_SECONDS , TimeUnit .SECONDS );
@@ -168,6 +174,7 @@ public void onEvent(@Nullable QuerySnapshot snapshots,
168
174
*/
169
175
void detachListener () {
170
176
// [START detach_errors]
177
+ // [START firestore_listen_detach]
171
178
Query query = db .collection ("cities" );
172
179
ListenerRegistration registration = query .addSnapshotListener (
173
180
new EventListener <QuerySnapshot >() {
@@ -184,6 +191,7 @@ public void onEvent(@Nullable QuerySnapshot snapshots,
184
191
185
192
// Stop listening to changes
186
193
registration .remove ();
194
+ // [END firestore_listen_detach]
187
195
// [END detach_errors]
188
196
}
189
197
@@ -192,6 +200,7 @@ public void onEvent(@Nullable QuerySnapshot snapshots,
192
200
*/
193
201
void listenErrors () {
194
202
// [START listen_errors]
203
+ // [START firestore_listen_handle_error]
195
204
db .collection ("cities" )
196
205
.addSnapshotListener (new EventListener <QuerySnapshot >() {
197
206
@ Override
@@ -209,6 +218,7 @@ public void onEvent(@Nullable QuerySnapshot snapshots,
209
218
}
210
219
}
211
220
});
221
+ // [END firestore_listen_handle_error]
212
222
// [END listen_errors]
213
223
}
214
224
0 commit comments