Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top