问题
I am very new to Android App development and I have to execute a very simple use case. I have a service and I want it to send some data to my android app. This data for simplicity can be a JSON object with a text field like so:
{"text": "Hello world"}
And in the app, when this message is received, I want to display "Hello world". So every time a request is sent from the service, I want the message to be updated on the app. How can I accomplish this? All the documentation available on the internet focuses on making calls to the service. I want to make a call to the Android app. Thank you
回答1:
For sending messages from the server to the app, you'd want to use a push messaging solution such as Firebase Cloud Messaging, Amazon SNS, or others.
Normally, it's difficult to send a message from a server to an app, because you can't simply open a connection to a device that's not set up as a server. These services interact with a service that's already running on the device, such as Google Play Services on Android or Apple Push Notification Service on iOS, to deliver messages to the device on demand.
For an overview of how to set up Firebase Cloud Messaging in an Android app, check out the documentation here.
Disclosure: I work for Google, who make Firebase
来源:https://stackoverflow.com/questions/62601025/how-to-send-data-over-https-to-an-android-application