How to send pushnotification to andoroid using php

Hi Friends,

 

Today I am discussing about push notification on android device through PHP. To know more about push notification you can visit http://en.wikipedia.org/wiki/Push_technology . Now I am going to tell you how to send push notification to android using PHP. I have created a function that you can use for push notification for android.

function sendPushNotification($apiKey,$registrationIDs,$message)
{

$url = ‘https://android.googleapis.com/gcm/send’;

$fields = array(
                ‘registration_ids’  => $registrationIDs,
                ‘data’              => array( “message” => $message ),
                );

$headers = array(
                    ‘Authorization: key=’ . $apiKey,
                    ‘Content-Type: application/json’
                );

// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
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_POSTFIELDS, json_encode( $fields ) );
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
return $result;
}

 

In this function you will need to send 3 parameters

1) Api Kye:- API key (provide by googe)

2) Registration ID:- An array that contain the list of device token on which you have to sent the notification.

3) Message:- Message that you want to sent in push notification.

Use this function keep smiling. 🙂

Thanks

 

 

Share This Post

Recent Articles

Leave a Reply

ERROR: si-captcha.php plugin: GD image support not detected in PHP!

Contact your web host and ask them to enable GD image support for PHP.

ERROR: si-captcha.php plugin: imagepng function not detected in PHP!

Contact your web host and ask them to enable imagepng for PHP.

© 2018 Networkocean. All rights reserved. Site Admin · Entries RSS · Comments RSS
Powered by WordPress · Designed by Theme Junkie