问题
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