0

I'm developing a simple phoning application for Android, but I'm having trouble implementing an important functionality.

When I make a call in an Android's default phone app, if I place the phone next to my ear, the screen goes black and it gets temporarily disabled so the user don't accidentally press the virtual buttons.

I already know how to use the proximity sensor, but how can I temporarily disable the screen?

  • start by http://developer.android.com/guide/topics/sensors/sensors_position.html#sensors-pos-prox – njzk2 Jul 16 '15 at 19:37
  • Yes you will need to use the distance sensor to determine if the phone is close to an object. Once you have determined this you can set the screen to turn off. – Eric E Jul 16 '15 at 19:38
  • also, developer.android.com/reference/android/os/PowerManager.html#PROXIMITY_SCREEN_OFF_WAKE_LOCK but for API 21+ only – njzk2 Jul 16 '15 at 19:40
  • I already know how to use the proximity sensor, I edited the question to reflect that. My main question is how to temporarily turn off the screen. – João Lourenço Jul 16 '15 at 20:34

1 Answers1

1

You might want to have a look at these answers

Turn off screen programmatically when face is close the screen on Android

android: turn off screen when close to face

Android: How to turn screen on and off programmatically?

Community
  • 1
  • 1
Jitin Jassal
  • 137
  • 2
  • 13