How do I send custom sounds in FCM notifications via HTTP legacy?

Asked

Viewed 28 times

1

I’m using a standard webview APP with FCM integration; and I’ve always sent notifications to users through the legacy HTTP protocol site. It still works normally, but the custom sounds stored in the app’s RES/RAW folder only touch users with Android 7.2 or lower; on Android Oreo and higher only plays the default sound. There’s nothing in the documentation reporting on this. I know the problem occurred for local notifications as well and was solved by adding the notification channels. But in FCM http legacy I found nothing that could solve the problem.

    include('banco_dados.php');

$consulta = mysqli_query($cnx,"SELECT controle, apelido FROM usuarios WHERE id= '$id'");
$dados = mysqli_fetch_assoc($consulta);
$controle = $dados['controle'];
$apelidomsg = $dados['apelido'];

define( 'API_ACCESS_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxxx' );
$registrationIds = $controle;

 $msg = array
      (
    'body'  => $apelidomsg,
    'title' => $title,
    'icon'  => 'myicon',
    'sound' => $sonido,
    'tag' => 'skp'
      );

$fields = array
        (
            'to'        => $registrationIds,
            'notification'  => $msg
        );


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

    $ch = curl_init();
    curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/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 );

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.