How can I make Xamarin.forms TapGestureRecognizer make an audible click sound?

NancyFilesNancyFiles USMember, University

I am using a TapGestureRecognizer for an Image on an Android device. When I tap the image, it is working properly, except there is no audible click noise like there is when I tap any other button.

Answers

  • adamkempadamkemp USInsider, Developer Group Leader mod

    I'm not familiar with any Android buttons that cause click sounds other than the keyboards.

  • NancyFilesNancyFiles USMember, University

    When the Touch Sounds device settings is turned on, I get an audible sound when I tap buttons I created in Xamarin forms.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    I had never heard of this. According to this you need to call PlaySoundEffect(SoundEffects.Click) on a View instance. That means you'll need a custom renderer for this.

  • NancyFilesNancyFiles USMember, University

    Not sure if I can get the View since I'm using Xamarin Forms. I was able to get the following to work, but it's the notification sound:
    using Android.Media;
    try
    {
    Android.Net.Uri soundURI = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
    Ringtone r = RingtoneManager.GetRingtone(Forms.Context, soundURI);
    r.Play();
    }
    catch (Exception) {
    Android.Util.Log.Error(logTag, "Unable to play sound");
    };

    The following works too:
    ToneGenerator tg = new ToneGenerator (Android.Media.Stream.Notification, Volume.Max);
    tg.StartTone(Tone.PropNack);

  • adamkempadamkemp USInsider, Developer Group Leader mod

    If you use a custom view renderer then you can get a View instance.

  • NancyFilesNancyFiles USMember, University

    That's true. There's usually more than one why to do something.

  • PaulHoetsPaulHoets USMember ✭✭

    @adamkemp said:
    I'm not familiar with any Android buttons that cause click sounds other than the keyboards.

    I believe it depends on the api, and it sometimes is a setting on the phone itself, is it not?

    Any idea how to elegantly do this in Forms?

Sign In or Register to comment.