How to send data over HTTP(S) to an Android application

给你一囗甜甜゛ 提交于 2020-06-28 08:06:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!