I need suggestions for sending push notifications

I am currently in my android app that I need to implement push notifications, I already have a google API key and that's it, and you have activated push notifications on the key.

I understand that notifications are sent from the server downstream to the application.

Essentially what I am trying to do is whenever my database is updated I want to send a message to certain devices without a message in response.

But what I don't really understand is sending a message down the body to the phone. How this is done, I have just sent upstream HTTP messages to my server and I am somewhat confused as to how to do this. Are there any server applications that can do this, and if so, what am I looking for.

+3


source to share


6 answers


There are several ways to send a downstream message from the server. One of them uses PHP. You can write a PHP script to send a message to GCM (which actually sends a notification to the phone).

This is what I came up with for my application:

I have used curl



    $url = 'https://android.googleapis.com/gcm/send';
$receive_id=$_POST['receiver_key'];
$message=$_POST['message'];

$registrationIDs = array( $receive_id);


    $fields = array(
        'registration_ids' => $registrationIDs,
        'data' => array( "message" => $message ),
    );
    $headers = array(
        'Authorization: key=' . $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_HEADER, true);
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($fields) );

 $curl_result = curl_exec( $ch );

      

What I actually did was let the application run this PHP script to run when needed. This is what is called sending a downstream message from the server.

+2


source


You do not handle the downstream telephone yourself. You have several parts of the process that look like this.

Install yourself with GCM (looks like you already did)



Ask the app to register this device for GCM and configure the handler to accept push messages. This is usually done when the application starts up, so yes, you will need to communicate with the device first. You also usually want to give them the option to opt out of push messages. Basically, part of the application looks like here

You have a script that runs when the database is updated. You can then call GCM to send a message, passing the message and registration IDs of specific devices as your payload.

+2


source


A little more searching will give you this:

Android push notifications using Google App Engine

This should be what you are looking for. Here the google site link also gives some insight on it: http://developer.android.com/google/gcm/http.html

+1


source


Since you are looking for some specific server functionality with push notifications, I would suggest going with some software that does this for you, rather than writing all the code for the server.

One such program that I know is IBM MobileFirst (formerly known as Worklight) ... Its got a push notification that ... There could be many more server programs out there that do the same

+1


source


Have a look at dev push server . All you need to do is just paste your google api key and registration id in the appropriate fields and send push to your client. Also you can see the source code of this push server on Bitbucket

+1


source


I just want to update this post just in case this information might be helpful to others. So basically what I did, when the user installs the app, they register with Google to get the registration id, after which it will send it to my database when I need it later. Now when the user updates the database by adding a post or allowing a comment, it will run a php script that runs my web servlet on tomcat, from where my tomcat serplet queries my database and finds out who (registration id) to send the post.

0


source







All Articles