I am sending data messages from our app server calling firebase api to users.Users are receiving the notifications but sound is not playing when notification arrives.
here is the code
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
sendNotification(remoteMessage);
}
private void sendNotification(RemoteMessage message) {
Intent intent;
intent = new Intent(this, HomeActivity.class);
Log.d(TAG, message.getData().toString());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(this, defaultSoundUri);
r.play();
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(message.getData().get("title"))
.setContentText(Html.fromHtml(message.getData().get("body")))
.setAutoCancel(true)
// .setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
saveMessage(message);
} catch (Exception e) {
e.printStackTrace();
}
}
what could be the problem???