Simplified Coding

  • About
  • Contact Us
  • Advertise
  • Privacy Policy
You are here: Home / Android Application Development / Android Advance / Create Chat App for Android using GCM Part 1

Create Chat App for Android using GCM Part 1

May 30, 2016 by Belal Khan 53 Comments

Hello friends, in this post I will show you How to Create Chat App for Android using PHP, MySQL and GCM. I have already posted about GCM and Push Notifications in my earlier post as these are very important for creating our chat app. So in this post we will create a simple chat room where many users can interact with each other.

This post was very lengthy so I divided it into two parts. 

Part 1: This part will cover about creating server side codes and APIs.
Part 2: In this part we will actually build our chat application.

Contents

  • 1 Create Chat App for Android Live Demo
  • 2 Prerequisite to Create Chat App for Android
  • 3 Create Chat App for Android Tutorial
    • 3.1 Creating Database
    • 3.2 Creating RESTful API
    • 3.3 Testing the API
    • 3.4 Sharing is Caring:
    • 3.5 Related

Create Chat App for Android Live Demo

You can also check this video demonstrating the final app that we will make in this tutorial.

You can also get a live demo of the app that we will be building from below. Just download the apk from the link given and install it to your device. But you need two device to check it.

Download APK

If you tested the apk and want to know how to code it then lets move ahead.

Prerequisite to Create Chat App for Android

  • You should follow the previous Android Push Notification Tutorial using GCM.
  • You should also follow the REST API tutorial using SLIM Framework.
  • Other than the above mentioned tutorial we will be using PHP and MySQL you need a local server like wamp or xampp for it.

It is highly recommended that you go through the above mentioned tutorial before moving ahead on this Create Chat App for Android Tutorial. So lets begin.

Create Chat App for Android Tutorial

In this post we will create server side APIs and in the next post we will built the android application. I am using WAMP server. You can also use other server’s basically what is needed is PHP and MySQL.  So lets start with creating database.

Creating Database

  • This is our database model.

database

  • So as you can see we have two tables one is users and other is messages. To create the above tables just copy the following SQL to your phpmyadmin.

database.sql
ZSH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
-- Created by Simplified Coding https://www.simplifiedcoding.net
-- Last modification date: 2016-05-30 15:41:34.537
 
-- tables
-- Table: messages
CREATE TABLE messages (
    id int NOT NULL AUTO_INCREMENT,
    message varchar(100) NOT NULL,
    users_id int NOT NULL,
    sentat timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT messages_pk PRIMARY KEY (id)
);
 
-- Table: users
CREATE TABLE users (
    id int NOT NULL AUTO_INCREMENT,
    name varchar(50) NOT NULL,
    email varchar(50) NOT NULL,
    gcmtoken text NOT NULL,
    CONSTRAINT users_pk PRIMARY KEY (id)
);
 
-- foreign keys
-- Reference: messages_users (table: messages)
ALTER TABLE messages ADD CONSTRAINT messages_users FOREIGN KEY messages_users (users_id)
    REFERENCES users (id);
 
-- End of file.

  • Now we have our database. Time to code our API.

Creating RESTful API

  • I am using PHP Storm as I personally feel it is the best IDE. So whatever IDE you are using open it and create a new PHP Project in the WAMP’s root directory (c:/wamp/www). I have created SimplifiedCodingChat.
  • Now you have to create the following folder structure as shown in the below screenshot.

rest api

  • First download SLIM Framework 2.x and paste it inside your libs folder.
  • Now inside include folder create 3 php files Config.php, DbConnect.php and DbOperation.php.
  • First come inside Config.php and write the following code.

Config.php
PHP
1
2
3
4
5
6
7
8
9
10
11
12
<?php
 
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
define('DB_NAME', 'db_simplifiedcodingchat');
 
define('USER_CREATED_SUCCESSFULLY', 0);
define('USER_CREATE_FAILED', 1);
define('USER_ALREADY_EXISTED', 2);
 
define('GOOGLE_API_KEY','YOUR GOOGLE API KEY');

  • You may need to change the value of the first 4 constants according to your MySQL database. And you also need to put your Google API Key. If you don’t know what is the google api key please go through the Android Push Notification Tutorial using GCM first.
  • Now inside DbConnect.php write the following code. It is used to connect with the MySQL Database.

DbConnect.php
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
 
class DbConnect
{
    private $conn;
 
    function __construct()
    {
    }
 
    /**
     * Establishing database connection
     * @return database connection handler
     */
    function connect()
    {
        require_once 'Config.php';
 
        // Connecting to mysql database
        $this->conn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
 
        // Check for database connection error
        if (mysqli_connect_errno()) {
            echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }
 
        // returing connection resource
        return $this->conn;
    }
}

  • In DbOperation.php we will define functions for all the database related operations. Write the following code in DbOperation.php.

DbOperation.php
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
 
class DbOperation
{
    private $conn;
 
    //Constructor
    function __construct()
    {
        require_once dirname(__FILE__) . '/Config.php';
        require_once dirname(__FILE__) . '/DbConnect.php';
        // opening db connection
        $db = new DbConnect();
        $this->conn = $db->connect();
    }
 
    //Function to create a new user
    public function createUser($name, $email)
    {
        if (!$this->isUserExists($email)) {
            $stmt = $this->conn->prepare("INSERT INTO users(name, email) values(?, ?)");
            $stmt->bind_param("ss", $name, $email);
            $result = $stmt->execute();
            $stmt->close();
            if ($result) {
                return USER_CREATED_SUCCESSFULLY;
            } else {
                return USER_CREATE_FAILED;
            }
        } else {
            return USER_ALREADY_EXISTED;
        }
    }
 
    //Function to get the user with email
    public function getUser($email)
    {
        $stmt = $this->conn->prepare("SELECT * FROM users WHERE email=?");
        $stmt->bind_param("s", $email);
        $stmt->execute();
        $user = $stmt->get_result()->fetch_assoc();
        return $user;
    }
 
    //Function to check whether user exist or not
    private function isUserExists($email)
    {
        $stmt = $this->conn->prepare("SELECT id FROM users WHERE email=?");
        $stmt->bind_param("s", $email);
        $stmt->execute();
        $stmt->store_result();
        $num_rows = $stmt->num_rows;
        $stmt->close();
        return $num_rows > 0;
    }
 
    //Function to store gcm registration token in database
    public function storeGCMToken($id, $token)
    {
        $stmt = $this->conn->prepare("UPDATE users SET gcmtoken =? WHERE id=?");
        $stmt->bind_param("si", $token, $id);
        if ($stmt->execute())
            return true;
        return false;
    }
 
    //Function to get the registration token from the database
    //The id is of the person who is sending the message
    //So we are excluding his registration token as sender doesnt require notification
    public function getRegistrationTokens($id){
        $stmt = $this->conn->prepare("SELECT gcmtoken FROM users WHERE NOT id = ?;");
        $stmt->bind_param("i",$id);
        $stmt->execute();
        $result = $stmt->get_result();
        $tokens = array();
        while($row = $result->fetch_assoc()){
            array_push($tokens,$row['gcmtoken']);
        }
        return $tokens;
    }
 
    //Function to add message to the database
    public function addMessage($id,$message){
        $stmt = $this->conn->prepare("INSERT INTO messages (message,users_id) VALUES (?,?)");
        $stmt->bind_param("si",$message,$id);
        if($stmt->execute())
            return true;
        return false;
    }
 
    //Function to get messages from the database
    public function getMessages(){
        $stmt = $this->conn->prepare("SELECT a.id, a.message, a.sentat, a.users_id, b.name FROM messages a, users b WHERE a.users_id = b.id ORDER BY a.id ASC;");
        $stmt->execute();
        $result = $stmt->get_result();
        return $result;
    }
 
}

  • Inside libs folder create a new folder named gcm and inside it create a new file named gcm.php and write the following code. This file will handle our push notifications.

gcm.php
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
 
class GCM
{
    function __construct()
    {
 
    }
 
    //This function will send message to the given registration ids
    //We are also passing a message that is actually an array containing the message
    public function sendMessage($registration_ids, $message) {
        $fields = array(
            'registration_ids' => $registration_ids,
            'data' => $message,
        );
        //In this function we are calling the main method responsible for sending push notification
        //it is sendPushNotification
        return $this->sendPushNotification($fields);
    }
 
    //This is the main method responsible for sending push notification
    //I have already explained it in previous tutorials
    private function sendPushNotification($fields){
        include_once __DIR__ . '/../../include/Config.php';
 
        $url = 'https://android.googleapis.com/gcm/send';
 
        $headers = array(
            'Authorization: key=' . GOOGLE_API_KEY,
            'Content-Type: application/json'
        );
 
        $ch = curl_init();
 
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
 
        $result = curl_exec($ch);
        if ($result === FALSE) {
            die('Curl failed: ' . curl_error($ch));
        }
        curl_close($ch);
 
        return $result;
    }
}

  • Now come inside v1 folder and create a .htaccess file and write the following.

.htaccess
1
2
3
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]

  • Finally in v1 folder create index.php this file will handle all the API calls.

index.php
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
require_once '../include/DbOperation.php';
require_once '../libs/gcm/gcm.php';
require '.././libs/Slim/Slim.php';
 
\Slim\Slim::registerAutoloader();
 
$app = new \Slim\Slim();
 
// User id from db - Global Variable
$user_id = NULL;
 
 
/**
* User Registration
* url - /register
* method - POST
* params - name, email
*/
$app->post('/register', function () use ($app) {
    //Verifying parameters
    verifyRequiredParams(array('name', 'email'));
 
    //Response array
    $response = array();
 
    //Getting request parameters
    $name = $app->request->post('name');
    $email = $app->request->post('email');
 
    //Vaidating email
    validateEmail($email);
 
    //Creating a db object
    $db = new DbOperation();
 
    //INserting user to database
    $res = $db->createUser($name, $email);
 
    //If user created
    //Adding the user detail to response
    if ($res == USER_CREATED_SUCCESSFULLY) {
        $response["error"] = false;
 
        $user = $db->getUser($email);
 
        $response['id'] = $user['id'];
        $response['name'] = $user['name'];
        $response['email'] = $user['email'];
 
        echoResponse(201, $response);
 
        //If user creating failes adding error to response
    } else if ($res == USER_CREATE_FAILED) {
        $response["error"] = true;
        $response["message"] = "Oops! An error occurred while registereing";
        echoResponse(200, $response);
 
        //If user already exist
        //adding the user data to response
    } else if ($res == USER_ALREADY_EXISTED) {
        $response["error"] = false;
        $user = $db->getUser($email);
 
        $response['id'] = $user['id'];
        $response['name'] = $user['name'];
        $response['email'] = $user['email'];
 
        echoResponse(200, $response);
    }
});
 
/*
* URL: /send
* Method: POST
* parameters: id, message
* */
 
//This is used to send message on the chat room
$app->post('/send', function () use ($app) {
 
    //Verifying required parameters
    verifyRequiredParams(array('id', 'message'));
 
    //Getting request parameters
    $id = $app->request()->post('id');
    $message = $app->request()->post('message');
    $name = $app->request()->post('name');
 
    //Creating a gcm object
    $gcm = new GCM();
 
    //Creating db object
    $db = new DbOperation();
 
    //Creating response array
    $response = array();
 
    //Creating an array containing message data
    $pushdata = array();
    //Adding title which would be the username
    $pushdata['title'] = $name;
    //Adding the message to be sent
    $pushdata['message'] = $message;
    //Adding user id to identify the user who sent the message
    $pushdata['id']=$id;
 
    //If message is successfully added to database
    if ($db->addMessage($id, $message)) {
        //Sending push notification with gcm object
        $gcm->sendMessage($db->getRegistrationTokens($id), $pushdata);
        $response['error'] = false;
    } else {
        $response['error'] = true;
    }
    echoResponse(200, $response);
});
 
/*
* URL: /storegcmtoken/:id
* Method: PUT
* Parameters: token
* */
 
//This will store the gcm token to the database
$app->put('/storegcmtoken/:id', function ($id) use ($app) {
    verifyRequiredParams(array('token'));
    $token = $app->request()->put('token');
    $db = new DbOperation();
    $response = array();
    if ($db->storeGCMToken($id, $token)) {
        $response['error'] = false;
        $response['message'] = "token stored";
    } else {
        $response['error'] = true;
        $response['message'] = "Could not store token";
    }
    echoResponse(200, $response);
});
 
/*
* URL: /messages
* Method: GET
* */
 
//This will fetch all the messages available on the database to display on the thread
$app->get('/messages', function () use ($app){
    $db = new DbOperation();
    $messages = $db->getMessages();
    $response = array();
    $response['error']=false;
    $response['messages'] = array();
    while($row = mysqli_fetch_array($messages)){
        $temp = array();
        $temp['id']=$row['id'];
        $temp['message']=$row['message'];
        $temp['userid']=$row['users_id'];
        $temp['sentat']=$row['sentat'];
        $temp['name']=$row['name'];
        array_push($response['messages'],$temp);
    }
    echoResponse(200,$response);
});
 
 
//Function to validate email
function validateEmail($email)
{
    $app = \Slim\Slim::getInstance();
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $response["error"] = true;
        $response["message"] = 'Email address is not valid';
        echoResponse(400, $response);
        $app->stop();
    }
}
 
 
//Function to display the response in browser
function echoResponse($status_code, $response)
{
    $app = \Slim\Slim::getInstance();
    // Http response code
    $app->status($status_code);
    // setting response content type to json
    $app->contentType('application/json');
    echo json_encode($response);
}
 
 
//Function to verify required parameters
function verifyRequiredParams($required_fields)
{
    $error = false;
    $error_fields = "";
    $request_params = $_REQUEST;
    // Handling PUT request params
    if ($_SERVER['REQUEST_METHOD'] == 'PUT') {
        $app = \Slim\Slim::getInstance();
        parse_str($app->request()->getBody(), $request_params);
    }
    foreach ($required_fields as $field) {
        if (!isset($request_params[$field]) || strlen(trim($request_params[$field])) <= 0) {
            $error = true;
            $error_fields .= $field . ', ';
        }
    }
 
    if ($error) {
        // Required field(s) are missing or empty
        // echo error json and stop the app
        $response = array();
        $app = \Slim\Slim::getInstance();
        $response["error"] = true;
        $response["message"] = 'Required field(s) ' . substr($error_fields, 0, -2) . ' is missing or empty';
        echoResponse(400, $response);
        $app->stop();
    }
}
 
 
 
function authenticate(\Slim\Route $route)
{
    //Implement authentication if needed
}
 
 
$app->run();

  • Thats it for the API Coding. Now you need a REST Client to Test the API. You can use Postman for google chrome.

Testing the API

  • You can use Postman for chrome or any other REST Client to test your API. The final API we built is shown in the following table

Base URL: http://localhost/SimplifiedCodingChat/v1/

URL Method Parameters
register POST name,email
send POST id, message
storegcmtoken/:id PUT token
messages GET
  • If you are having some problems or troubles you can get my php project for this Android Chat App for Android Tutorial from the link given below (You need to unlock the link).

 Download REST API Project

So thats all for this part friends. You can follow the next part from the link given.

Create Chat Application in Android using GCM Part 2

In this part we will actually Create Chat App for Android using Android Studio. And yes feel free to ask by comments if having any troubles. Thank You 🙂

Sharing is Caring:

  • Tweet
  • Share on Tumblr
  • More
  • Pocket
  • Print
  • Email

Related

Filed Under: Android Advance, Android Application Development Tagged With: chat app for android source code, chat app for android tutorial, create chat app for android

About Belal Khan

I am Belal Khan, I am currently pursuing my MCA. In this blog I write tutorials and articles related to coding, app development, android etc.

Comments

  1. eblek says

    May 31, 2016 at 9:16 pm

    gcm is deprecated. do you think publishing a firebase chat room tutorial? there is not any in the web.

    Reply
    • Belal Khan says

      June 1, 2016 at 12:54 am

      Who said gcm is deprecated???

      Reply
      • eblek says

        June 1, 2016 at 10:33 am

        “Firebase Cloud Messaging (FCM) is the new version of GCM. It inherits the reliable and scalable GCM infrastructure, plus new features! See the FAQ to learn more. If you are integrating messaging in a new app, start with FCM. GCM users are strongly recommended to upgrade to FCM, in order to benefit from new FCM features today and in the future.”

        deprecated may be an assertive word, but gcm is not recommended by google for new projects.

        Reply
      • eblek says

        June 1, 2016 at 12:43 pm

        deprecated may be an assertive word, but gcm is not recommended by google for new projects.

        “Firebase Cloud Messaging (FCM) is the new version of GCM. It inherits the reliable and scalable GCM infrastructure, plus new features! See the FAQ to learn more. If you are integrating messaging in a new app, start with FCM. GCM users are strongly recommended to upgrade to FCM, in order to benefit from new FCM features today and in the future.”

        Reply
  2. Mary Corleone says

    June 1, 2016 at 7:42 am

    i test this whole script after following all the procedures, uploaded it into server, i’ve changed all required credentials (Config.php to be specific), and run it using POSTMAN, and this is the result:

    Slim Application Error

    did i miss something?

    p/s:

    …it takes me about 5-6 times sending this post, everytime i submit my post it returns me to a 403 page, i think your site has something on that makes it so irresponsive…

    Reply
  3. Mary Corleone says

    June 1, 2016 at 7:50 am

    .. who said that Google Cloud Messaging is deprecated? You might using other cloud messaging service, might be: xtify, urban airship, or pushy, but some people (mostly developers) say, (with “some people” with clause) that behind them is GCM .

    Reply
  4. Mary Corleone says

    June 1, 2016 at 7:51 am

    .. who said that Google Cloud Messaging is deprecated? You might using other cloud messaging service, might be: xtify, urban airship, or pushy, but some people (mostly developers) say, (with “some people” with clause) that behind them is GCM . am telling you, the best of knowlegde , it is not.

    Reply
  5. eblek says

    June 1, 2016 at 10:31 am

    “Firebase Cloud Messaging (FCM) is the new version of GCM. It inherits the reliable and scalable GCM infrastructure, plus new features! See the FAQ to learn more. If you are integrating messaging in a new app, start with FCM. GCM users are strongly recommended to upgrade to FCM, in order to benefit from new FCM features today and in the future.”

    deprecated may be an assertive word, but gcm is not recommended by google for new projects.

    Reply
  6. eblek says

    June 1, 2016 at 12:44 pm

    deprecated may be an assertive word, but gcm is not recommended by google for new projects.

    “Firebase Cloud Messaging (FCM) is the new version of GCM. It inherits the reliable and scalable GCM infrastructure, plus new features! See the FAQ to learn more. If you are integrating messaging in a new app, start with FCM. GCM users are strongly recommended to upgrade to FCM, in order to benefit from new FCM features today and in the future.”

    Reply
    • Belal Khan says

      June 1, 2016 at 12:46 pm

      Yeah I have published a Firebase tutorial too..

      Reply
      • M Ibrahim Hayat says

        August 31, 2018 at 11:29 pm

        bilal i need a little help from you brother. then please mail me back bro thanks

        Reply
  7. Zishan says

    June 2, 2016 at 3:54 pm

    Hello Belal Brother,Please Upload a chatting tutorial about a single chat like friend to friend chat using Firebase GCM,thanks in advance

    Reply
  8. Shaun says

    June 12, 2016 at 5:13 am

    Hi Sir,
    The Tutorial is best and works excellently on XAMPP.

    But when I upload the files to the online web server, the app malfunctions.

    I have changed the Config.php page like DBname, Host while hosting it to the online Web Server. I have also changed the path given in the app.

    I will thankful for your help!
    Thank You!

    Reply
    • Belal Khan says

      June 12, 2016 at 9:33 am

      It also work on online server.. as the apk I given for the demo is working on online server.. there may some misconfiguration in your server.. check that

      Reply
      • Shaun says

        June 12, 2016 at 5:19 pm

        Thank You, Sir for your reply.

        But I made all the changes in the configuration to the best of my knowledge. But the malfunction continues.

        Please can you list me the changes I should make for online server.

        Will thankful for your help!
        Thank You!

        Reply
        • Mary Corleone says

          June 25, 2016 at 11:54 am

          i had the same experienced, the scripts are fully working fine on local server but some negative issue exists on putting all scripts on online server, and this i figure out: error exists not because of buggy script, it is because of capability of your main host or hosting i should say. You might using a shared server, am i right? take note that in shared server mysqlnd driver is not enabled, in summary, you need to use such or some mysqli prepared statements with object oriented programming using such VPS or Dedicated Server.Because those host services provide full root access and mysqlnd driver run by default.

          Reply
    • Sid says

      July 29, 2016 at 4:14 am

      hi Shaun I also using web server but there is one problem i.e. getting 404 Page Not Found Error, if your app is running then help me.

      Reply
  9. Rehaan says

    June 14, 2016 at 2:38 pm

    Happy Ramadan belal.I have a questions you know the essential things required in the startup field , so why don”t you do it.Or you are already doing something.But above all thank you for these lovely tutorials.

    Reply
  10. Aman says

    June 20, 2016 at 10:50 am

    Fatal error: Call to undefined method mysqli_stmt::get_result() in
    /home/test/public_html/test/chatting/include/DbOperation.php on line
    41

    Reply
    • Mary Corleone says

      June 25, 2016 at 11:28 am

      i had the same experienced, the scripts are fully working fine on local server but some negative issue exists on putting all scripts on online server, and this i figure out: error exists not because of buggy script, it is because of capability of your main host or hosting i should say. You might using a shared server, am i right? take note that in shared server mysqlnd driver is not enabled, in summary, you need to use such or some mysqli prepared statements with object oriented programming using such VPS or Dedicated Server.Because those host services provide full root access and mysqlnd driver run by default.

      Reply
  11. Tze Ha says

    July 17, 2016 at 11:25 am

    why i received the message “Parse error: syntax error, unexpected ‘x’ (T_STRING) in C:\wamp\www\gcm_chat1\v1\index.php on line 6”, I don’t know what happen because I followed your example exactly, please help me to solve the problem, because I quite new in android

    Reply
  12. ishita says

    July 18, 2016 at 6:16 am

    i am getting 404 page 🙁

    Reply
    • william says

      August 3, 2016 at 12:32 pm

      HELP IDEM

      Reply
  13. ishita says

    July 18, 2016 at 6:38 am

    hii i m getting 404 error plz guide mee..

    Reply
  14. Sid says

    July 29, 2016 at 4:06 am

    Getting 404 Page Not Found Error.
    Help!

    Reply
  15. rosh says

    August 8, 2016 at 11:06 am

    Tutorial is good.Working At localhost perfectly but didn,t work inside the shared server.Didn’t get any responses why??????

    Reply
  16. yasser says

    August 15, 2016 at 3:48 pm

    There is a mistake that needs a fix. DbOperation.php line 21
    Before: $stmt = $this->conn->prepare(“INSERT INTO users(name, email) values(?, ?)”);

    When I tried to register it gave me an error but

    After:

    $stmt = $this->conn->prepare(“INSERT INTO users(name, email,gcmtoken) values(?, ?,’A’)”);
    It worked for me by inserting gcmtoken.

    Reply
  17. Hans says

    September 2, 2016 at 10:21 am

    Thanks you are really good in explaining this.
    Can this be uploaded to lets say Google app engine instead of a local server?
    What changes is needed for that?

    Reply
  18. Diya patel says

    October 10, 2016 at 8:54 am

    Hello, i want this demo project using FCM.

    Reply
  19. vahid says

    November 19, 2016 at 11:02 am

    hey please help us how can
    Resolve 404 error

    Reply
    • Belal Khan says

      November 19, 2016 at 12:13 pm

      enable apache rewrite module

      Reply
  20. Foxy says

    January 2, 2017 at 5:38 pm

    Will this still work,i saw a comment about been depreciated

    Reply
    • Belal Khan says

      January 3, 2017 at 4:50 am

      NO it is not deprecated but you should use firebase cloud messaging instead. Check this fcm tutorial to replace gcm with fcm https://www.simplifiedcoding.net/firebase-cloud-messaging-android/

      Reply
  21. Bruno Mendes says

    January 25, 2017 at 11:01 pm

    please help us how can
    Resolve 404 error??

    My apache rewrite module is ok

    i use xampp

    Reply
  22. Mani says

    February 1, 2017 at 5:51 am

    Hi,

    I get an error ” java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean .helper.AppController.isLoggedIn()” and the app crashes.

    Can u please help??

    Reply
  23. UP007 says

    February 3, 2017 at 9:41 am

    Please, help!
    Error: ————
    404 Page Not Found
    The page you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly. If all else fails, you can visit our home page at the link below.

    Visit the Home Page
    ———-
    Database and table is created
    Installed Denwer

    Reply
  24. afsar says

    February 7, 2017 at 10:07 am

    Apk i downloaded that itself not working properly, after entering email..it again asks for email…

    Reply
  25. Sonam says

    February 13, 2017 at 7:15 am

    enter name and enter email. submit button..only loaded the progress bar not open Next Actvity

    Reply
  26. Fabian says

    March 10, 2017 at 10:10 pm

    Hello, where can I find the v1 folder?
    Thank you very much!

    Reply
  27. priyesh says

    March 30, 2017 at 8:35 am

    enter name and enter email. submit button..only loaded the progress bar not open Next Actvity

    Reply
  28. priyesh says

    March 30, 2017 at 8:38 am

    when i am enter name and enter email but it still load progress bar but do not display next act.so pls give me fast solution as soon as possible

    Reply
    • the eng says

      April 23, 2017 at 1:49 pm

      do you find what is the problem,same here!!

      Reply
  29. sameer says

    April 6, 2017 at 7:29 am

    hello sir ,
    when i have insert name and the email id in the field it will inserted in the database but couldn’t create the gcm tocken in “users” table

    Reply
  30. bhumi says

    June 10, 2017 at 12:19 pm

    hello when i run this php code it show me error Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log. …this error how i solve this please please help me and reply soon as possible..please help me belal

    Reply
  31. SHASHI JAISWAL says

    June 24, 2017 at 2:54 pm

    your code does not let connectivity to server and neither you reply to my queries?

    Reply
    • Belal Khan says

      August 24, 2017 at 4:51 am

      You have surely done something wrong.. we are making an updated post using FCM so please have patience and we will post the updated content soon

      Reply
  32. Hekuran says

    August 22, 2017 at 10:11 am

    Hello guys, I implemented the code of this tutorial ( and changed some pieces of it regarding to the needs of my app).
    But I have a problem. When I try to use $gcm->sendMessage(…), I got an error as a result, saying : Error 411 (Length Required)!!, and That’s an error. POST requests require a Content-length header. That’s all we know.
    Hope you guys can help me

    Reply
    • Belal Khan says

      August 24, 2017 at 4:49 am

      You should try using FCM now.. and We are creating a tutorial for the same using FCM.

      Reply
  33. SHASHI JAISWAL says

    August 22, 2017 at 10:10 pm

    Don’t host such website if you do not have time to reply.
    You waste both you and your viewer time.

    Reply
    • Belal Khan says

      August 24, 2017 at 4:49 am

      Say what is the problem? We will try to help you

      Reply
  34. Ritu says

    November 13, 2017 at 3:21 am

    PHP Fatal error: Call to undefined method mysqli_stmt::get_result()

    Reply
  35. kevin says

    January 8, 2018 at 9:39 am

    Hi, when the FCM version will be available? need it urgently

    Reply
  36. m7mdhassballa says

    March 14, 2018 at 11:38 am

    i keep getting 404 not found on postman and browser .i don’t know what’s the problem, i already enabled Apache rewrite module.
    please help.

    Reply

Leave a Reply to eblek Cancel reply

Your email address will not be published. Required fields are marked *

Search




Download our Android App

Simplified Coding in Google Play

About Me

Belal Khan

Hello I am Belal Khan, founder and owner of Simplified Coding. I am currently pursuing MCA from St. Xavier's College, Ranchi. I love to share my knowledge over Internet.

Connect With Me

Follow @codesimplified
Simplified Coding

Popular Tutorials

  • Android JSON Parsing – Retrieve From MySQL Database
  • Android Login and Registration Tutorial with PHP MySQL
  • Android Volley Tutorial – Fetching JSON Data from URL
  • Android Upload Image to Server using Volley Tutorial
  • Android TabLayout Example using ViewPager and Fragments
  • Retrieve Data From MySQL Database in Android using Volley
  • Firebase Cloud Messaging Tutorial for Android
  • Android Volley Tutorial – User Registration and Login
  • Android Upload Image to Server Using PHP MySQL
  • Android Navigation Drawer Example using Fragments




About Simplified Coding

Simplified Coding is a blog for all the students learning programming. We are providing various tutorials related to programming and application development. You can get various nice and simplified tutorials related to programming, app development, graphics designing and animation. We are trying to make these things simplified and entertaining. We are writing text tutorial and creating video and visual tutorials as well. You can check about the admin of the blog here and check out our sitemap

Quick Links

  • Advertise Here
  • Privacy Policy
  • Disclaimer
  • About
  • Contact Us
  • Write for Us

Categories

Android Advance Android Application Development Android Beginners Android Intermediate Ionic Framework Tutorial JavaScript Kotlin Android Others PHP Advance PHP Tutorial React Native

Copyright © 2017 · Simplified Coding· All rights Reserved. And Our Sitemap.All Logos & Trademark Belongs To Their Respective Owners·

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.