2

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

Oscar Moncayo
  • 188
  • 6
  • 20

2 Answers2

4

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

gunit
  • 3,700
  • 4
  • 31
  • 42
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).

Frank Wilson
  • 3,192
  • 1
  • 20
  • 29
  • II was thinking of doing the posting to the topic in an AsyncTask Class, but maybe I think that I need some authethication. – Oscar Moncayo Dec 04 '16 at 19:56
  • But I don't need some type of authenthication or URL or something that indicate my push message to the topic? – Oscar Moncayo Dec 04 '16 at 20:06
  • Thanks, I'll do it with App Engine Module in Android. Thanks! – Oscar Moncayo Dec 04 '16 at 21:46
  • 2
    If he's only having the devices publish, then he won't hit the 10,000 subscriptions issue right? I'm having a similar issue, and I don't want to deal with having to spin up a web server and worry about scaling/load balancing it. – gunit Jun 09 '17 at 00:17
  • 1
    You are right, the 10K subscription limit does not apply here. I have modified my answer accordingly and attributed you. Thanks for your input. – Frank Wilson Jun 09 '17 at 14:04
  • @FrankWilson: Do you know if it's secure to ship the Service Account Credentials with a client app? I mean the Google Service Account would only have permissions to publish to a topic, but the documentation seems to only mention shipping the GSA credentials to servers. – DoomGoober Sep 17 '20 at 01:26