How to play default button's sound on Xamarin.Android?
Xamarin.Android
:
var root = FindViewById<View>(Android.Resource.Id.Content);
root.PlaySoundEffect(SoundEffects.Click);
Android playSoundEffect(int soundConstant)
Xamarin.iOS
UIDevice.CurrentDevice.PlayInputClick();
Xamarin.Forms
via Dependency Service:
public interface ISound
{
void KeyboardClick () ;
}
And then implement the platform specific function.
iOS:
public void KeyboardClick()
{
UIDevice.CurrentDevice.PlayInputClick();
}
Android:
public View root;
public void KeyboardClick()
{
if (root == null)
{
root = FindViewById<View>(Android.Resource.Id.Content);
}
root.PlaySoundEffect(SoundEffects.Click);
}