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.
-
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...– SelvinMar 7, 2014 at 17:07
-
1you can test using pushtry.com– ArvindAug 19, 2016 at 21:30
4 Answers
Found a very easy way to do this.
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
-
1Not really :) For testing purposes, you can use 0.0.0.0/0 ip. it would work.– AdnanMar 4, 2014 at 14:29
-
4I get every time (with api key and device id: error":"InvalidRegistration Aug 14, 2014 at 3:29
-
4Please regenerate
API KEY
after, as it is not too safe to give them your key. Jan 16, 2015 at 17:16 -
6
-
2{ "error": "invalid_token", "error_description": "Invalid Value" } i found this. and getting invalid reg id.– AnandOct 20, 2015 at 11:58
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"
}
]
}
-
3I think this is the most clean and safe solution to test the GCM. Thanks! Jun 22, 2015 at 14:31
-
12Worked with a POST for me! Also do not forget to have "key=" in the Authorization header and not just the API_KEY Jul 1, 2015 at 17:03
-
3@Raphael Royer-Rivard you life saver, i was missing "key=" in the Authorization header Nov 29, 2015 at 17:38
-
3There 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".– LiangjunDec 8, 2015 at 17:56
-
3
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.
-
1
-
1Just 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..)– GreywireMar 15, 2016 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– ThylleMay 31, 2018 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 Aug 3, 2018 at 16:45
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
-
2You 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. Send– ArvindAug 22, 2016 at 6:11