I made a script using PHP to send my phone a notification using firebase cloud messaging everything is ok but I need to include with the notification a sound
<?php
function sendoo($to='',
$data = array()){
$apiKey = 'hide';
$fields = array ('to' => $to, 'notification' => $data);
$headers = array('Authorization: key=' .$apiKey,'Content-Type:
application/json');
$url = 'https://fcm.googleapis.com/fcm/send';
$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_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
$to = "hide";
$data = array(
'body' => 'new order'
);
print_r(sendoo($to, $data));
?>
Do you want custom sound or default sound?
First put this line of code
Notification notification = new Notification(icon, tickerText, when);
Then in order to play default sound put this:
notification.defaults |= Notification.DEFAULT_SOUND;
If you want in order to play custom sound save an mp3 file and access it like that:
notification.sound = Uri.parse("file:///sdcard/notification/notification.mp3");
After that use the notifaction manger to send the notification. Note: only use one of these methods if you use both the application will use the default sound. :)
Try this modification in $fields
$fields = array(
'to' => 'something',
'sound' => 'default',
'body' => 'hello',
'title' => 'Message',
'_displayInForeground'=> 'true',
'channelId'=>'default',
);
channelId is important to fire the sound!!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.