Reputation: 33
I'm making an app for work that's meant to be a portal for patrons using Java in Android Studio. I've set up Firebase Cloud Messaging, Authentication, and a Realtime database to store users. I can send out push notifications easily from the Cloud Console, but I was wondering if there was a way to send push notifications to all devices without using the console?
My reasoning is that I don't want someone in HR accidentally deleting a user, but I would like them to be able to send out push notifications for situations such as closings. Is there any way to do that, either through a remote push to all devices, or a restricted version of the console so that changes can't be made? I'm pretty new to this, so forgive me if this is a simple question.
Upvotes: 3
Views: 7101
Reputation: 1857
You can send notifications to all devices, provided all devices are subscribed to a topic.
You can create a php file that is responsible for sending the information to firebase using the api token.
If it has served you, I would appreciate your approval of my comment, regards.
Notification.php:
$token = 'test'; // Topic or Token devices here
$url = "https://fcm.googleapis.com/fcm/send";
// api key
$serverKey = ''; // add api key here
$notification = array('title' => 'Welcome StackOverFlow' , 'body' => 'Testing body', 'sound' => 'default', 'badge' => '1');
$data = array('extraInfo'=> 'DomingoMG');
$arrayToSend = array('to' => $token, 'notification' => $notification, 'priority'=>'high', 'data'=> $data);
$json = json_encode($arrayToSend);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: key='. $serverKey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
//Send the request
$response = curl_exec($ch);
//Close request
if ($response === FALSE) {
die('FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);
Upvotes: 2
Reputation: 317467
You can use the Firebase Admin SDK from a backend or other machine that you fully control. It has an API for sending messages to devices where you have collected their device ID tokens.
There is no additional console or GUI for sending messages - you will have to write code if the console doesn't do what you want.
Upvotes: 2