0

I have one android application so

  1. my application is running foreground
  2. and I click power button
  3. Beep sound comes
  4. my phone goes into sleep
  5. When i again click power button
  6. my phone wake up
  7. I unlock my phone
  8. again Beep sound comes
  9. screen goes to my application screen

Here i do not want that beep in case 3 and case 8 so how can i do that from my application code?

Edit: I know this can be done by from setting->sound->screen lock sound checkbox but i need to do this just for my app only no matter whats general setting for screen lock sound is selected.

Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222

2 Answers2

1

This isn't something you need to program - this setting is in Android settings, sound settings, "Screen lock sounds". Since that's an option for the settings app, I doubt you can change it from your app. (Changing other applications' data is forbidden unless it's root/system app)

NoBugs
  • 9,310
  • 13
  • 80
  • 146
  • there is not something you overwrite that sound effect on power button for your application's activity? – Jeegar Patel Nov 15 '13 at 07:13
  • Looks like I may be wrong - see the other answer. (I didn't know there was an api for that). Why would you want inconsistent behavior, only in your app though? – NoBugs Nov 15 '13 at 15:34
1

Put below code in your android app where you want to turn off the screen lock sound.

If you using Activity use below code :

Settings.System.putInt(getContentResolver(), "lockscreen_sounds_enabled",
                            0);

If you using Fragment use below code :

Settings.System.putInt(getActivity(),getContentResolver(), "lockscreen_sounds_enabled",
                            0);

To enable it again you can set 1 instead of 0.

Thanks

dreamcrash
  • 47,137
  • 25
  • 94
  • 117
Ravi Bhayani
  • 151
  • 3