I am working on a Cloud messaging application, and I am using the Firebase cloud messages, by this code
public class NotificationHelper {
public static void displayNotification(Context context, String title, String body) {
Uri alertSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context, MainActivity.CHANNEL_ID)
.setSmallIcon(R.drawable.ic_gift )
.setContentTitle(title)
.setContentText(body)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setSound(alertSound);
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context);
notificationManagerCompat.notify(1, mBuilder.build());
}
}
and this is the service.
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
if (remoteMessage.getNotification() != null) {
String title = remoteMessage.getNotification().getTitle();
String text = remoteMessage.getNotification().getBody();
NotificationHelper.displayNotification(getApplicationContext(), title, text);
}
}
}
and this is the manifest XML code
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
and the messages coming but without any sounds, I do not know what it the wrong thing in my code, please anyone can help me