0

I've been poking around documentation but I can't seem to find an answer to my question. Unlike Apple, that separates production and development APNs, which allows for testing, is there any similar functionality for Android? We have apps in production, but need to test push notifications in-house without affecting our user base. Is the only way to achieve this, through making two Firebase projects?

Edit: Not all of the test devices are on sight as some of our testing happens through beta tests. Thank you

VirtualProdigy
  • 1,637
  • 1
  • 20
  • 40

1 Answers1

0

It's simple. Get a device/ Emulator you want to test your notification on. Run your app. Get the firebase key for that device by writing :

 String firebaseKey = FirebaseInstanceId.getInstance().getToken();

Now, in your server use this code to send notification to that device only.

  function sendSingleNotification($id, $message){

$fields = array(
    'to' => $id,
    'data' => $message,
);

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

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

$ch = curl_init();
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_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
    die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
return $result;

}
Basu
  • 763
  • 8
  • 27