0

I have an AppWidget (part of my app). I want there to be no sound when the user clicks a button in the widget. How do I do this?

Eric Cochran
  • 8,414
  • 5
  • 50
  • 91

3 Answers3

2

CommonsWare answered it: This is not a method on RemoteViews, and setSoundEffectsEnabled() is not a RemotableViewMethod, so the literal answer is incorrect. However, android:soundEffectsEnabled="false" in the layout file may work.

setting android:soundEffectsEnabled="false" in the xml layout file does indeed work!

Eric Cochran
  • 8,414
  • 5
  • 50
  • 91
1

As far as I know, you have to turn off notification sounds (pressing volume down, then selecting settings on it). The click sound is usually created by the OS (Samsung Android will have a click but google Nexus will not). The only other way I can think of is, if the widget is yours, create a custom button that overrides that particular functionality.

Raigex
  • 1,205
  • 12
  • 32
  • Well, if I could access the view directly, I could: myButton.setSoundEffectsEnabled(false); But, being a RemoteViews, I don't think this is possible. – Eric Cochran Sep 05 '13 at 18:18
  • No i meant, is the widget part of your app (you developed it) or are you trying to mute someone elses widget. – Raigex Sep 05 '13 at 18:19
  • Oh, the AppWidget is mine. It is part of my app. – Eric Cochran Sep 05 '13 at 18:19
  • setSoundEffectsEnabled(false) will not always work, Best bet is to remove the functionality via extending the Button and removing that functionality. You will need to go into the source code for that fix though. – Raigex Sep 05 '13 at 18:21
  • See CommonsWare's answer. Thanks for the help. – Eric Cochran Sep 05 '13 at 18:28
0

Add the following line of code to disable the click sound,

yourbutton.setSoundEffectsEnabled(false);
Spring Breaker
  • 8,233
  • 3
  • 36
  • 60
  • I cannot access the view directly because it is an AppWidget. – Eric Cochran Sep 05 '13 at 18:18
  • 2
    @NightlyNexus: This is not a method on `RemoteViews`, and `setSoundEffectsEnabled()` is not a `RemotableViewMethod`, so the literal answer is incorrect. However, `android:soundEffectsEnabled="false"` in the layout file may work. – CommonsWare Sep 05 '13 at 18:19
  • @CommonsWare Yep, that did it. I should have thought of that haha. Setting stuff in xml is the best way to work with RemoteViews. – Eric Cochran Sep 05 '13 at 18:27
  • I am glad that solved your problem.Credit goes to @CommonsWare – Spring Breaker Sep 05 '13 at 18:33
  • @CommonsWare regarding `setSoundEffectsEnabled` i have set it to false on one of my button but no effect. it still produce sound. tested on Google Nexus 10 – Muhammad Babar Jan 01 '14 at 12:10
  • @CommonsWare problem was with `performClick()` which does not respect the `setSoundEffectsEnabled(false)`. Android's Bad :P – Muhammad Babar Jan 01 '14 at 12:14