Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Android / Problem setting up push notifications using FCM

Author
Message
Charlie09
6
Years of Service
User Offline
Joined: 11th Sep 2017
Location:
Posted: 27th Feb 2019 11:29 Edited at: 27th Feb 2019 14:08
Hello,
I tried to set up push notification using Firebase Cloud Messaging for my app and I was succesfull ..... to some degree. The problem is that notifications appear for AppGameKit Player and not my app as you can see in the pictures:



This is the code I use in my app to setup notifications:

SetPushNotificationKeys( "SenderID","id from firebase project settings, cloud messaging under SenderID")
result = PushNotificationSetup()
if ( result = 1 )
token$ = GetPushNotificationToken()
// and code that writes notification token into database

and code i use on server to send notification:

function SendPushNotificationAndroid( $deviceToken, $message, $title )
{
// Replace with real SERVER API key from Google APIs
$apiKey = "server key from firebase settings .....i also tried legacy key with the same results";

// Set POST variables
$url = 'https://fcm.googleapis.com/fcm/send';

$fields = array(
'to' => $deviceToken,
'notification' => array( "title" => $title, "body" => $message ),
'priority' => "high",
);

$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
echo "Sending\n";
$result = curl_exec($ch);

// Close connection
curl_close($ch);

echo "Result: " . $result ."\n";
}

Anyone has any idea why this doesnt work as it should ? Any help would be appreciated.
Also if you have other ideas on how to get the notifications working I am all ears.

[edit]: problem with pictures

Attachments

Login to view attachments
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 15th Mar 2019 01:08
its allot easier for people to read and respond to your code if you place it in code brackets

This is done by clicking the code menu at the top of the editing text window
For code clicking it once then entering your code and clicking it again Using appgamekit for AppGameKit code etc if there isn't a category use the "misc code"

fubar
2D Analyst
AGK Developer
19
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 27th Mar 2019 02:50
This is pretty cool. I had no idea AppGameKit was even capable to integrate with push notifications. I've only implemented push notifications via native apps or hybrid apps via cordova/phonegap.

Login to post a reply

Server time is: 2024-03-29 13:28:56
Your offset time is: 2024-03-29 13:28:56