Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android push notification how to play default sound

I'm using MixPanel to send push notification and on the custom payload I add the following code: {"sound":"default"} the problem Is that no sound gets played when I receive the notification. Does anyone have a solution for this?

like image 241
LS_ Avatar asked Sep 03 '14 07:09

LS_


People also ask

How do I make notification app default sound?

Choose the appropriate category and select Alert. On the Notification category page, scroll down to the Sound section. It shows the default tone enabled for the app. Tap Sound and select your desired notification tone from the list to change the presets.

Can push notifications have sound?

On Android devices, it is possible to choose individual push notification sounds.


3 Answers

  mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
like image 33
Mehroz Munir Avatar answered Nov 15 '22 10:11

Mehroz Munir


Maybe this helps found here code will look like this.

Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
like image 168
marcel Avatar answered Nov 15 '22 08:11

marcel


In order to send notification + sound using mixpanel, you need to do the following:

  • add the following code to the onCreate:

            NotificationCompat.Builder mBuilder =
                    new NotificationCompat.Builder(this);
            mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
            Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
            r.play();
    
  • Send notification from mixpanel and see it received. This will send notification on create with default sound configured on the user's device.

like image 30
Eyal Sooliman Avatar answered Nov 15 '22 09:11

Eyal Sooliman