97

Update: GCM is deprecated, use FCM

I am implementing Google Cloud Messaging in my application. Server code is not ready yet and in my environment due to some firewall restrictions I can not deploy a test sever for push notification. What I am looking for is a online server which would send some test notifications to my device to test my client implementation.

Adnan
  • 4,945
  • 4
  • 23
  • 44
  • You did delete other post thats why im writing here :-) NotificationListenerService was added in api 18... Just store ids in SharedPreferences as int array and do some logic to chceck size of array if after adding new id is bigger than you need take first element and cancel... – Selvin Mar 07 '14 at 17:07
  • 1
    you can test using http://www.pushtry.com – Arvind Aug 19 '16 at 21:30

4 Answers4

168

Found a very easy way to do this.

Open http://phpfiddle.org/

Paste following php script in box. In php script set API_ACCESS_KEY, set device ids separated by coma.

Press F9 or click Run.

Have fun ;)

<?php


// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' );


$registrationIds = array("YOUR DEVICE IDS WILL GO HERE" );

// prep the bundle
$msg = array
(
    'message'       => 'here is a message. message',
    'title'         => 'This is a title. title',
    'subtitle'      => 'This is a subtitle. subtitle',
    'tickerText'    => 'Ticker text here...Ticker text here...Ticker text here',
    'vibrate'   => 1,
    'sound'     => 1
);

$fields = array
(
    'registration_ids'  => $registrationIds,
    'data'              => $msg
);

$headers = array
(
    'Authorization: key=' . API_ACCESS_KEY,
    'Content-Type: application/json'
);

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
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 );
curl_close( $ch );

echo $result;
?>

For FCM, google url would be: https://fcm.googleapis.com/fcm/send

For FCM v1 google url would be: https://fcm.googleapis.com/v1/projects/YOUR_GOOGLE_CONSOLE_PROJECT_ID/messages:send

Note: While creating API Access Key on google developer console, you have to use 0.0.0.0/0 as ip address. (For testing purpose).

In case of receiving invalid Registration response from GCM server, please cross check the validity of your device token. You may check the validity of your device token using following url:

https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=YOUR_DEVICE_TOKEN

Some response codes:

Following is the description of some response codes you may receive from server.

{ "message_id": "XXXX" } - success
{ "message_id": "XXXX", "registration_id": "XXXX" } - success, device registration id has been changed mainly due to app re-install
{ "error": "Unavailable" } - Server not available, resend the message
{ "error": "InvalidRegistration" } - Invalid device registration Id 
{ "error": "NotRegistered"} - Application was uninstalled from the device
Adnan
  • 4,945
  • 4
  • 23
  • 44
159

POSTMAN : A google chrome extension

Use postman to send message instead of server. Postman settings are as follows :

Request Type: POST

URL: https://android.googleapis.com/gcm/send

Header
  Authorization  : key=your key //Google API KEY
  Content-Type : application/json

JSON (raw) :
{       
  "registration_ids":["yours"],
  "data": {
    "Hello" : "World"
  } 
}

on success you will get

Response :
{
  "multicast_id": 6506103988515583000,
  "success": 1,
  "failure": 0,
  "canonical_ids": 0,
  "results": [
    {
      "message_id": "0:1432811719975865%54f79db3f9fd7ecd"
    }
  ]
}
Michael
  • 8,464
  • 2
  • 59
  • 62
19

Pushwatch is a free to use online GCM and APNS push notification tester developed by myself in Django/Python as I have found myself in a similar situation while working on multiple projects. It can send both GCM and APNS notifications and also support JSON messages for extra arguments. Following are the links to the testers.

Please let me know if you have any questions or face issues using it.

Amyth
  • 30,315
  • 25
  • 83
  • 129
  • 1
    Please explain your downvote. – Amyth Mar 09 '16 at 15:14
  • 1
    Just what I needed, works perfectly (tried the postman one, which sorta worked, but didnt cause the message to appear on my device when my app was not opened..) – Greywire Mar 15 '16 at 19:07
  • Hi Amyth i get this error on your site: "HTTP Error 401: Invalid (legacy) Server-key delivered or Sender is not authorized to perform request." Not sure what to do? I just created a Google Project and tried using the project ID and the project Number for the SenderID and added your site to the "Accept requests from these HTTP referrers (websites)" in the google API settings. Best regards Rasmus – Thylle May 31 '18 at 13:47
  • Note this URL is no longer support: *As of April 10, 2018, Google has deprecated GCM. The GCM server and client APIs are deprecated and will be removed as soon as April 11, 2019.* [GCM info](https://developers.google.com/cloud-messaging/http-server-ref) – Stinky Towel Aug 03 '18 at 16:45
7

Postman is a good solution and so is php fiddle. However to avoid putting in the GCM URL and the header information every time, you can also use this nifty GCM Notification Test Tool

Varun
  • 1,841
  • 14
  • 16
  • 2
    You can use this online tester which supports both Android and iOS. Easy to use simple website http://www.pushtry.com 1. Select you .p12 file 2. Enter device token3 3. Select environment Sandbox or production 4. Enter message 5. Send – Arvind Aug 22 '16 at 06:11