0

I am currently developing an app and its notification system is working well. Except when i send a message from firebase to the phone the notification does not make a sound (default phone sound). The question is what is going wrong in my java program.

private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, page1.class);//**The activity that you want to open when the notification is clicked
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);


    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("FCM Message")
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());


}
Axel
  • 13,939
  • 5
  • 50
  • 79

2 Answers2

0

Repalce following line in your code:

 Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
R.R.M
  • 780
  • 4
  • 10
0
Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.cutomSound);

This way You can access your custom notification sound.

Sajith Vijesekara
  • 1,324
  • 2
  • 17
  • 52