Back

How to use Realtime Client in Android App Java?

  • 0
  • Android
  • Realtime
retr122
9 Dec, 2023, 16:59

Hello! I tried to use Realtime Subscription to receive User Document's updates, but in examples at the Appwrite Docs don't found correctly example to my Java. Briefly, I need to receive when User Document's updates and check "chats" (List<String>) parameter. If this changed, make a notification. Is it possible to receive this directly in Realtime Object? How to subscribe Realtime Channel/Channels?

TL;DR
Summary: The user is asking for help with using the Realtime Client in an Android app using Java. They are experiencing errors with their code and have questions about how to use the Realtime subscription and handle the payload data. They also want to know if it is possible to receive updates for a specific parameter in a User Document and how to subscribe to Realtime channels. Solution: - The user can pass a type to indicate the type of the payload in the Realtime response event. - For subscribing to Realtime changes, the user can use the `RealtimeSubscription` class and provide a lambda expression to handle the events, channels
Drake
9 Dec, 2023, 17:03

Yes this is possible. What do you have now and what's wrong?

retr122
9 Dec, 2023, 17:03

i don't know how to use RealtimeResponseListener (syntacsys)

retr122
9 Dec, 2023, 17:03

and what usually means Object in that case

Drake
9 Dec, 2023, 17:05

What's your code?

retr122
9 Dec, 2023, 17:09

something like this ```String[] channels = new String[0]; realtime.subscribe(channels, new RealtimeResponseEvent<>((result21, error21) -> { if (error21 != null) { error21.printStackTrace(); return; }

TypeScript
                                            Log.d("Appwrite", result21.toString());
                                        }));```
Drake
9 Dec, 2023, 17:13

So you'll need to specify the channels, but besides that, what's wrong?

retr122
9 Dec, 2023, 17:15

when i typing result21 as object, it means <lambda parameter>? i don't understand it in that case

Drake
9 Dec, 2023, 17:16

So you're getting a build error?

retr122
9 Dec, 2023, 17:19

this also, error21.printStackTrace() and result21.toString()

Drake
9 Dec, 2023, 17:20

Would you please share the exact error?

retr122
9 Dec, 2023, 17:21

But when I do other functions, I receive io.appwrite.models, in example io.appwrite.models.Account and i getting parameters from this. Is this analogue like io.appwrite.models as result21?

retr122
9 Dec, 2023, 17:21

cannot resolve method in both cases

Drake
9 Dec, 2023, 17:22

Possibly...please share the full exact error

retr122
9 Dec, 2023, 17:33

I solved this, but I had some questions. Is the realtime subscription returns payload and what can I do with that? What kind of data I can receive from payload?

Drake
9 Dec, 2023, 17:34

Payload would match the event. For example, if you're subscribed to documents, the payload will be a document

retr122
9 Dec, 2023, 17:35

I can cast it to Appwrite Document if subscribe in Document Updates? If I subscribe to Appwrite Collection Changes?

retr122
9 Dec, 2023, 17:49

i rewrited code as ```RealtimeSubscription realtimeSubscription = realtime.subscribe(channelsArray, new RealtimeResponseEvent<>((events, channels, eventTimestamp, eventPayload) -> {

TypeScript
                                        }));``` and receiving Multiple non-overriding abstract methods found in interface java.util.Collection error.
Drake
9 Dec, 2023, 18:13

Yes, you can't change the parameters

Drake
9 Dec, 2023, 18:15

Realtime response event is a generic...is that what's it's called in Java? You can pass a type to indicate what the type of the payload is. See https://github.com/appwrite/sdk-for-android/blob/c5974e005753b963bfc18d09c7f56bea97e2173c/library/src/main/java/io/appwrite/models/RealtimeModels.kt#L23

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more