Google Cloud. Pub/Sub Android App

时间秒杀一切 提交于 2021-02-18 17:59:50

问题


I'm try to send data throught pub/sub library to my topic in GoogleCloud

projects/navigator-cloud/topics/navigator-location

Here is a project of a google map with a overlay image of a building, which I should use. I want to publish a JSON with some info like this: {"Username": "oscarhmg", "Location": "labproto", "Timestamp": "2016-12-04T15:29:05Z" }.

When the topic receive this info, in the building map appears a marker(This map shows in my application in a web view). This functionality is already implemented, what I still do not understand at all is how to pass the message to publish on this topic through my android application. Any help would appreciate it


回答1:


Check out this Android Things tutorial that has the device directly publishing messages to Google Cloud Pub/Sub without going through a web server. The way to do the authentication is by building the .json credential into the Android app.

https://github.com/androidthings/weatherstation




回答2:


As @gunit points out there is a way to connect an android app demonstrated by androidthings. I have not used this method myself.

You will have to manually create a google cloud api token from the console and pass it in while using the API.

When connecting a mobile client directly to PubSub but you may need to setup the topic permissions to enable access.

Alternatively, you can make a web service that your android app connects to (via HTTP POST) to publish a message. That web service will then put the message it receives into the PubSub topic.

If you use use appengine to build the webservice solution then it will automatically be authenticated to work with pubsub (I can confirm the python api does this at least).



来源:https://stackoverflow.com/questions/40962871/google-cloud-pub-sub-android-app

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