Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,774 members, 7,810,013 topics. Date: Friday, 26 April 2024 at 06:43 PM

Android Programming With Google Cloud Chat - Expert - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Android Programming With Google Cloud Chat - Expert (1460 Views)

2. Learning Android Programming. / 1. Learning Android Programming / Android Programming: PC Is Not Intel Virtual Technology Enabled, What Can I Do? (2) (3) (4)

(1) (Reply) (Go Down)

Android Programming With Google Cloud Chat - Expert by Nobody: 11:28pm On Jul 04, 2015
Good evening people,
We are going to look at the basics of building a chat application using google app engine/google cloud chat API

Technologies involved
- Android studio, Android Emulator

You need to have the following installed on your pc:
- Java SDK: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
- Android studio: http://tools.android.com/download/studio


Disclaimer: please let us observe decency on this thread. If you feel that you can do a better job than me, please click here to signify that or click here if you are still not satisfied.
Re: Android Programming With Google Cloud Chat - Expert by Drniyi4u(m): 4:28am On Jul 05, 2015
following!
Re: Android Programming With Google Cloud Chat - Expert by Nobody: 7:27am On Jul 05, 2015
There is only requirement to this tutorial, you must have tried out google chat - the least being that you go through the QuickStart tutorial from start to finish.
At the end of that quickstart tutorial, you will have written an application that connects to google cloud, and you can send a message by
gradle. You might need an android phone connected to your PC to test out the quickstart tutorial.

Note: if you are running android studio on windows. After running the application in your phone connected to pc/android studio.
To send a message to it using gradle, you need to open the "terminal" at the bottom of your android window window (looks like ms-dos) and
put inside it: gradlew run -Pargs="<message>" (skip the ./ on windows)

You will find the quickstart tutorial on http://developers.google.com/cloud-messaging/android/start

Once at least one person has gotten that quickstart tutorial right, we shall continue this thread.

All I am going to add to it is:
- Ability to get a device ID with the APP
- Ability to send a message to that device via its ID with PHP - from any computer that has internet connection

And the thread will be over. . . .
Re: Android Programming With Google Cloud Chat - Expert by CRAZYMADMAN(m): 12:03pm On Jul 05, 2015
Off to read the bloody docs cry
Re: Android Programming With Google Cloud Chat - Expert by Nobody: 5:30pm On Jul 05, 2015
^^^Took me a long time to understand the gaddamn docs. . . .
Re: Android Programming With Google Cloud Chat - Expert by ballantyne: 5:38pm On Jul 05, 2015
Dhtml18, why do we have to send message to the messaging service using gradlew? Why not send the message directly from the mobile device?
Re: Android Programming With Google Cloud Chat - Expert by Nobody: 5:44pm On Jul 05, 2015
^^^If you read the gaddamn documentation, you will see that they only provided a way of sending messages via gradle (which is gaddamn silly).
Their tutorial has some minor issues with I will point out later. I just dont have time to start everything right from the beginning. But if you go through their tutorial, it will make my work easier and more specific.

After going through the tutorial on their site, I shall show you guys how to send messages from a device and receive it on another device,
and how to send message via CURL on any other programming language be it C,C++, even MSDOS console or wherever you like if you understand the basic idea.
Re: Android Programming With Google Cloud Chat - Expert by ballantyne: 7:02pm On Jul 05, 2015
Dhtml18, if the gradlew message method is part of a mistake from Google's tutorial, why not skip that part and go directly to the part where messages are sent from mobile devices? That is most likely to interest your audience the most. I think.

I mean, you are the one conducting the tutorial not Google. I am pretty sure almost everybody knows the location of the GCM docs.

I pointed that out because when I used GCM, I didn't use any gradlew method to send messages, so I think it can be skipped.
Re: Android Programming With Google Cloud Chat - Expert by Nobody: 8:39pm On Jul 05, 2015
^^^You might skip out the gradle part, but at least complete the google tutorial first - it is a pre-requisite to this tutorial.

Anyway, I shall go ahead with my own tutorial very shortly - I am just trying to avoid unnecessary questions - that is why I made the already existing GCM tutorial a compulsory course before this tutorial.
Re: Android Programming With Google Cloud Chat - Expert by Nobody: 10:20pm On Jul 05, 2015
Start from here: https://developers.google.com/cloud-messaging/android/client

Let me provide the steps necessary to project the project both in google app engine and then android studio

1 Like

Re: Android Programming With Google Cloud Chat - Expert by Nobody: 10:20pm On Jul 05, 2015
We move on from here

2 Likes

Re: Android Programming With Google Cloud Chat - Expert by Nobody: 11:32pm On Jul 05, 2015
more screenshots

1 Like

Re: Android Programming With Google Cloud Chat - Expert by Nobody: 11:50pm On Jul 05, 2015
Here is a zip of the project's app folder inside android studio. It contains manifest, activity, gradle files etc. to help you jump-start the project.

Here is the way to customize the project.

go to line 33 in MainActivity.JAVA and replace the Project_Number with your sender's ID shown on the 5th screenshot (under the API KEY)
go to line 37 in IntentRegistrationService.JAVA and replace the same step as above for authorizedEntity

In order to test the app, you are going to require your android phone connected to your pc. Alternatively, you can test using bluetacks.

To use bluestacks from android studio, make sure you start bluestacks first. You will see an emulator in the list called Unknown Emulator - well, that will be bluestacks.


When you run it on your phone, you ought to get a final message showing something like this:

Token retrieved and sent to server!
You can now use gcmsender to send downstream messages to this app.
Device Registration ID: APA91bHAR-1By4P3WXu0HvpHb1I_Xe8SXZdsHOiIR4-jJN4URoDKr6OpB4r7dffu3wSLZjZUktlMWYnsRvFo6Cig3zbM2Cw0Ve3GxC6xhodKMA-kmfTo9S4

The Device Registration ID however must be different. It changes from device to device. You need to save this somewhere within your application so that you can recognize devices and other clients can send messages to them.


Now I remember mentioning that I shall show how to send messages to the APP via PHP. Well here is a push notification script written in PHP.

How it works is this:
visit line 20/21 to put the device_id generated in the arrray for you to send a message to
visit line 43 of the script push.php (attached to this post) and edit the API KEY to the same one shown on screen 5.

You can run the script on your localserver - so far as it has internet connection. You ought to get a response that looks like this:
{"multicast_id":9054501877260519103,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1436135433219134%c3e4f6e0f9fd7ecd"}]}

I am re-attaching the screen 5 to this post once again for emphasis.

Finally, in order to be able to send messages via Android to a Device, well, the gcm quickstart tutorial provides a GCMSender.java that shows how to do that. I am attaching that JAVA code to this post - alternatively, you can use HTTP client to do just that.

This thread is not really for beginners as such, so if you find it a bit complicated, well that is because it is really complicated but also simple once you get to understand it better.

In case you are wondering how this translates to a real-life chat. This is just a part of the whole game, you still need a chat application server (that might be a topic for another thread someday).

And that will be all, I shall take questions from this point. . . . . . . . . . . . . . . . . . . . . . . . .

1 Like

Re: Android Programming With Google Cloud Chat - Expert by Nobody: 11:56pm On Jul 05, 2015
I tested all the above as I am posting, I am a practical programming and not a copy-paster, I only post codes that I have tested to be working.
Re: Android Programming With Google Cloud Chat - Expert by CRAZYMADMAN(m): 9:31am On Jul 06, 2015
Nice work boss. Having some issues with my laptop.
Will continue the tutorial hopefully this night
Re: Android Programming With Google Cloud Chat - Expert by Nobody: 10:03am On Jul 06, 2015
You are welcome.

(1) (Reply)

Buy A Top Level .com Domain Name, Ssl Support And Host For N5,000 (per Year) / Android Creation And Software / Please Do A Q&A Ask Me Anything Thread

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 30
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.