Search code examples
androidxamarin.formsportable-class-library

Xamarin.forms How to play an android notification sound


I am using Xaminn.Forms PLC project, right now I am trying to set sound for notification on android project, I add the notification to my project using:

assembly: Xamarin.Forms.Dependency (typeof (NotificationService))]

on the following my code used to display the notification:

   var notification = new Notification.Builder (Application.Context)
    .SetContentTitle (message.Short_Message.ToString ())
    .SetContentText (message.Long_Message.ToString())
    .SetSmallIcon (Resource.Mipmap.ic_launcher)  
    .SetStyle(new Notification.BigTextStyle().BigText(message.Long_Message))   
    .SetPriority((int)NotificationPriority.Max) 
    .SetContentIntent(OpenAppOnCLickOnNotificaton)   
    .SetLights(255,1000,1000)
    .Build ();

    var manager = Application.Context.GetSystemService (Application.NotificationService) as NotificationManager;
        manager.Notify (message.ID, notification);

Solution

  • You are able to use Default Notification Sound as the following:

      .SetDefaults(NotificationDefaults.Sound)