owntracks / android

OwnTracks Android App
http://owntracks.org
Eclipse Public License 1.0
1.37k stars 477 forks source link

Display a popup when receive a MQTT message #960

Closed ghost closed 3 years ago

ghost commented 3 years ago

Hi, I want to display a popup when receive a MQTT message. I think, the uithread should be updated when receive message but I am confusing, how the uithread can be updated. Could you guys give me some hints? Thanks in advance.

growse commented 3 years ago

What's the use case?

I'd probably start by managing the notification from the BackgroundService and then using the event bus to notify the service from the MessageProcessor when a message arrives matching whatever criteria you want. But I'm not sure that's the best way necessarily.

ghost commented 3 years ago

What's the use case?

I'd probably start by managing the notification from the BackgroundService and then using the event bus to notify the service from the MessageProcessor when a message arrives matching whatever criteria you want. But I'm not sure that's the best way necessarily.

My use case is, I have created a geofence backend, whenever user comes to a specific location, the user receives a MQTT message from backend, which says "welcome to location.....". I have modified function processIncomingMessage in MessageProcess.java and it displays MQTT message in the running terminal. But now, I want to diplay message "welcome to location....." as a popup and moreover, display a QRCode for user in order to enter the location.

ghost commented 3 years ago

What's the use case?

I'd probably start by managing the notification from the BackgroundService and then using the event bus to notify the service from the MessageProcessor when a message arrives matching whatever criteria you want. But I'm not sure that's the best way necessarily.

One more question, how can I connect BackgroundService to uithread?

growse commented 3 years ago

It's not obvious how a UI thread is relevant here. If you want to show a notification, you can manage that from the BackgroundService in the same way the other notifications are managed. Similarly, a toast can also be managed there. For anything more complex, you probably want a new activity, which you can probably start with an intent from either the service or maybe directly from the processor itself.

jpmens commented 3 years ago

@anhtu91 nice that you're interested in our app, and we always welcome new ideas for improving it or users' experience, but please understand that we cannot lead you through Android programming for modifying the app. We're just a very small team with @growse as our only Android developer and can spare only enough time to do this project in our spare time.

I think @growse has pointed you in the right directions, so I'm now going to close this issue.