0

I am sending a notifications via Firebase and I have issues with the sound. I've tried more solutions found on this forum, but still did not help.

The problem is - the sound is WORKING when I debug the app on my device, but the sound is NOT working after I publish my app to store... and this is what I don't understand.

The code:

        Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this,
            getString(R.string.default_notification_channel_id))
            .setSmallIcon(R.mipmap.ic_notify)
            .setContentTitle(title)
            .setContentText(body)
            .setAutoCancel(true)
            .setSound(sound)
            .setContentIntent(pi);

    NotificationManager manager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    assert manager != null;
    manager.notify(0, builder.build());

I want to play a default sound, nothing custom. No clue why it is working when testing and not working when published.

Darksymphony
  • 2,155
  • 30
  • 54
  • What API level? – greeble31 Nov 17 '19 at 00:05
  • testing on 26. I am using also channel if build version is O and higher. Now I added this: nChan.setSound(Settings.System.DEFAULT_NOTIFICATION_URI,attributes); still not sure if this help (will test after next release), but why it is working also without this line on API 26 when testing and not working when published – Darksymphony Nov 17 '19 at 10:43
  • I think it is [this](https://stackoverflow.com/questions/54796492/android-notification-channel-sounds-stop-working-when-using-sound-uris-that-refe/54796493#54796493), but I'd ask you to confirm that before I post an answer. If this is actually the case, your next push, with `DEFAULT_NOTIFICATION_URI`, will **not** work, and I recommend using [this](https://stackoverflow.com/a/38340580/6759241) to fix. You will also have to start with a fresh notification channel. You can either delete the original (`deleteNotificationChannel()`), or you can create a new one with a new, unique channel `id`. – greeble31 Nov 17 '19 at 14:28
  • your first link is about a custom raw.notification and the second link is about image resource. I need to use a default sound for each device – Darksymphony Nov 17 '19 at 14:44
  • Sorry, I should've been more clear. _Sometimes_ this bug is caused by the resource URI that's been persisted to the `NotificationChannel` getting "broken". If, for example, you used a different URI in an earlier version of the app, or if, say, your phone got upgraded, thereby changing the return value of `RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)`, then the old, broken URI stays in the `NotificationChannel`, no matter how many times you re-create it. You have to delete the channel entirely (or uninstall the app) in order to reset the URI. – greeble31 Nov 17 '19 at 14:50
  • hmm, ok then, I created a new channel ID. Again, it is working when testing, I will check if this will work after publishing. Before I have uninstalled my app and installed a new instance, but the notification sound was still not working, so let's see if the new channel id will help – Darksymphony Nov 17 '19 at 18:50

0 Answers0