Introduction
The GCM which was configured in previous article, now in this article we set up in android studio and configure the setting of our Android application. Here are the first two part of the series,
Set Up Google Play Services
- Open the Android Studio and simply choose the empty activity and create the project, I did it my previous android app project so don’t be confused I will explain each and delivery step.
- Move to Gradle Scripts.
- Open the build.gradle (Module: app)
Add GCM Activity & GCM Receiver Class
Now I add two java classes and this whole class is empty .In Image I show you how I add one class by single clicking on old java class and renaming it then saving it. follows the same rule for the second one class.
Add Permission
Now move to the AndroidManifest.xml file and add two permissions which are mandatory for GCM because by doing so we receive the message in our mobile.
Add GCM Activity Layout
Now simply add a blank layout in which you add one webview and give the id and set height and width property to match parent.
GCM Activity Class
Now move to GCM class and the first step is to extend with activity class then declare some class instance on class level making sure that for GoogleCloudMessaging class you want to import the GCM library which I showed you in previous step. Now in Oncreate method we call the webview which is created in previous step.
Register GCM && WEB
The first function onClick_register_gcm is basically to register the GCM with respect to it project ID which is shown in GCM Server and second method is doing the same but it registers to web and the third method is to perform these two functions in background method in this way we declare the async_task class.
Register AsyncTask for Web
The print method is basically we declare when we receive the message from GCM and set up by its own style. The second method is,
Register Device To WebServer
Now we make a method for register device to web server.
In the next article we will set up more settings and the next article is the last article of GCM.
Read more articles on Android: