How to temporarily disable screen in Android? - android

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?

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?

Related

How can I control the brightness of the device screen from my application in Jetpack Compose?

I am making a simple app in which I want that when I press a button the brightness of the device is set to maximum and when I press it again it goes back to how it was before. but I can't find anywhere on the internet how to do this, I've been trying several ways and I can't get it to work.

Lock screen (similar to pressing power button) on Android using Flutter

I'm creating an app and wanted to programmatically lock the device once the user taps a button.
I've searched online about this and the only stuff I found was lock screen orientation or some APIs to create a Lock-screen app.
I just wondering if a simple thing like thisDevice.lock(); or AndroidStuff.powerMgmt.lockScreen();. I mean, seems too basic and essential but I just can't find it

How to lock/unlock phone from Service in android?

I want to lock/unlock android using a service. I have checked other questions but none works. Some require to have my app in foreground and some I don't understand well enough. I want to show the lock screen if the device is password locked else home screen.
Just Turning screen on and off only will also work. Anyone know how to do it?
Edit 1:
I have tried things and managed to turn on(WakeLock) and off(DevicePolicyManager) screen. However, turning off screen does not lock phone only turns off the display. I use locknow(). This is acceptable but if possible can anyone tell how to lock phone?
Edit 2:
I can not lock my phone even by using physical lock button. It just turns off the screen.

Turn off device screen (without locking it)?

I'm making an app that uses the Proximity Sensor while a phone call is in progress. My main issue is that the device doesn't turn the screen off when I hold it up against my face (while talking on the phone). If anyone has a solution as to how to fix this, then my problem will be solved.
Right now though, I'm trying to manually switch the screen off to imitate the normal behavior of the phone app. I looked through a lot of other posts about this but most of them seem to have instructions on how to keep the screen turned ON. My case is the exact opposite... how do I programmatically set the device to turn it's screen off? I don't want it to lock itself or sleep (since the phone call will still be in progress), just turn the screen completely off.
Thanks!

Activate Android with touch instead of power button

We've got a tablet application for which we want to screen to timeout after a certain period, but would like the user to re-enable it by touching the screen instead of the 'power'-button on the side of the device.
What's the best approach (battery performance) to this?
Using a Partial Wake Lock (will the screen react?)
Disable the screen in some way, but keep everything (including touch response) working?
Other?
Any suggestions on this?
Gabriel,
Since this isn't possible by completely turning the screen off, you may want to just want to use a wake lock and dim the screen to its lowest setting as your 'timeout'. This way you can still accept screen touch events and 'wake' it from this state and bring it back to its previous brightness.
We've got a tablet application for which we want to screen to timeout after a certain period, but would like the user to re-enable it by touching the screen instead of the 'power'-button on the side of the device.
This is impossible except perhaps via custom firmware. If the screen is off, it will not respond to touch events.
Another thing you could do is use an app to turn screen off like ScreenStandby since it works in the background and can start on boot as well.
Out of curiosity, how can we go about contacting someone to help in creating a custom firmware like you did Gabriel?

Categories

Resources