Android: Test Push Notification online (Google Cloud Messaging) [closed]
I

4

99

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.

Inject answered 4/3, 2014 at 10:8 Comment(2)
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...Miscreant
you can test using pushtry.comValais
I
169

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
Inject answered 4/3, 2014 at 10:32 Comment(13)
The API access key is specific to the ip of server(generated from google console). If not we can do the API call from any serverAusterlitz
Not really :) For testing purposes, you can use 0.0.0.0/0 ip. it would work.Inject
I get every time (with api key and device id: error":"InvalidRegistrationMonteverdi
Some issue here always I am getting error InvalidRegistration, can someone help.Trafficator
kamleshwar, are you putting your device id here:array("YOUR DEVICE IDS WILL GO HERE" ); -- if yes perhaps you are adding some wrong device idInject
@kamleshwar "InvalidRegistration" means that your device ID is no good. Make sure you validate it Ex: check against https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=1/$token before storing it.Clishmaclaver
Please regenerate API KEY after, as it is not too safe to give them your key.Characterization
I'm getting [{"error":"NotRegistered"}]}. It was working just fine but suddenly it is showing this. HELP!Unconscious
Tushar, You application has been uninstalled.Inject
i keep on getting Unauthorized Error 401. any idea why?Biagio
{ "error": "invalid_token", "error_description": "Invalid Value" } i found this. and getting invalid reg id.Rivas
For anyone wondering, the registrationID corresponds to the deviceToken with Parse (and likely some other frameworks). The API_ACCESS_KEY was the server key generated in the Google API Console. Interestingly enough, the tokenInfo request still came back with InvalidValue even when the values I used created a successful request.Acidulate
it says The request's Authentification (Server-) Key contained an invalid or malformed FCM-Token (a.k.a. IID-Token). Error 401 i double check all key they are fine and working good with postmanPassably
L
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"
    }
  ]
}
Lunalunacy answered 11/6, 2015 at 10:46 Comment(8)
This is better but works with GET and not POST.Legionary
Worked with a POST for me! Also do not forget to have "key=" in the Authorization header and not just the API_KEYEwens
@Raphael Royer-Rivard you life saver, i was missing "key=" in the Authorization headerDallapiccola
There are a few keys you can create with Google Developer Console. Just in case you are not clear, to use with postman, you need to create a "Server Key".Alphorn
I have used restclient addon of firefox and successfully tested using above. ThnxRoselani
Only add key= before key value.Keynes
What is the "registration_ids" here? where to find them?Rosarosabel
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 infoPredestinate
E
18

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.

Eisenhart answered 8/3, 2016 at 15:7 Comment(3)
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..)Warfold
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 RasmusOrville
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 infoPredestinate
S
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

Sungod answered 9/12, 2015 at 15:26 Comment(1)
You can use this online tester which supports both Android and iOS. Easy to use simple website pushtry.com 1. Select you .p12 file 2. Enter device token3 3. Select environment Sandbox or production 4. Enter message 5. SendValais

© 2022 - 2024 — McMap. All rights reserved.