• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Help Use proximity sensor to disable screen while in pocket

Status
Not open for further replies.
Is there any way to bypass the dialog and have it start the service automatically? I have Tasker set to reboot my phone every night, then I would like it to start your program. But Tasker cannot check the checkboxes.

Thanks for your work on this. It's much needed.
I never do that. I mean I never restart the phone. :)
But despite all that, I had to rewrite the service, because Android might just stop and then restart any service without running the onStartCommand method of it.
I included the auto start service at boot time capability as default. It can be turned off in the dialog though.
proximitytoolextension - hu.copas.android.tools.ProximityTool - Google Project Hosting
 
New subversion (1.3). I added headset control. Wired headset only for now. It needs to have a microphone, legacy headphones make no difference.
When the service detects a headset, no matter if it's set to event controlled - it changes to general sensing because the device is most likely in pocket. This was necessarry because when you make a call and hang up on it after a while, the screen might (will) stay on and open to touches. While in pocket, this can lead to the already mentioned problems.
Downloads - proximitytoolextension - hu.copas.android.tools.ProximityTool - Google Project Hosting
 
I have only one suggestion regarding this tool. would it be possible to not only turn off screen, but also lock device (probably administrator rights needed)? it would be great to have the same action as lock screen (https://market.android.com/details?id=kennethcheng.com.lockscreen.free). turning only screen off makes my phone to turn screen on automatically when there is nothing near proximity sensor (after it was turned off ealier by this tool).

When the service detects a headset, no matter if it's set to event controlled - it changes to general sensing because the device is most likely in pocket

- does it mean that proximity sensor is constantly in use when headset is connected (I hope it will detect BT headset soon ;-))? or it is turned on only when screen turns on? I'm thinking about battery usage...
 
I've found a bit of a problem with this app. I just updated from the older "proximity tool" to Proximity Service 1.3. I have the Event Controlled option ticked, and this is on a Desire with the "official" Gingerbread update.

Here's the scenario. I have my Desire lying on my desk, with the screen off and locked. I then press the power button to activate the screen to check the status bar, without unlocking the device. Having done that, I press the power button again to turn the screen off.

The problem is that, because the device is still locked, and because the proximity sensor is right next to the power button, the proximity service activates just before I switch the screen off, when my hand approaches the button. Consequently, my button press is ignored by the device, and when I move my hand away, the screen comes back on.

The only way to turn my screen off in this locked situation is to (a) wait for it to time out by itself, (b) unlock the device and then switch it off, or (c) very carefully press the button without allowing my hand to go near the prox sensor.

Can you think of some clever way to stop this from happening e.g. only have the service active when the phone is locked with the screen off?
 
I have only one suggestion regarding this tool. would it be possible to not only turn off screen, but also lock device (probably administrator rights needed)? it would be great to have the same action as lock screen (https://market.android.com/details?id=kennethcheng.com.lockscreen.free). turning only screen off makes my phone to turn screen on automatically when there is nothing near proximity sensor (after it was turned off ealier by this tool).
Of course not. This service activates proximity sensing when the screen goes off AND the device gets locked within 30 seconds by purpose.
It's very complicated what you're asking for. There would be many checks, what's really going on at the moment. Just imagine. While in a conversation, the device would also lock itself. That wouldn't be the expected behavior. But I don't say that I won't think about it. I'll evaluate it while using it.
...- does it mean that proximity sensor is constantly in use when headset is connected (I hope it will detect BT headset soon ;-))? or it is turned on only when screen turns on? I'm thinking about battery usage...
Well, to point out again: this service is very simple. Since it's a service, it's always in the background, grabbing (now 5) different kinds of events. So, theoretically, it consumes around zero of the battery. When the situation demands, it activates the 'proximity wake-lock' which is a 'service' of Android. While this lock is held, Android shuts off the screen if anything's near the proximity sensor of the device. My service has nothing to do with the screen turn-offs. If something consumes battery, it will be Android's solution handling the proximity sensor. But this is still better than an unwanted situation.
Bluetooth headset detection is now implemented.
 
I've found a bit of a problem with this app. I just updated from the older "proximity tool" to Proximity Service 1.3. I have the Event Controlled option ticked, and this is on a Desire with the "official" Gingerbread update.
At the moment I use it with a cooked 2.1+3.0 Sense ROM but I'm planning to go to the official Desire with Android 2.3.3 but with Sense 2.1. This is because of many things like the dialer copy&paste, etc.
Here's the scenario. I have my Desire lying on my desk, with the screen off and locked. I then press the power button to activate the screen to check the status bar, without unlocking the device. Having done that, I press the power button again to turn the screen off.
The problem is that, because the device is still locked, and because the proximity sensor is right next to the power button, the proximity service activates just before I switch the screen off, when my hand approaches the button. Consequently, my button press is ignored by the device, and when I move my hand away, the screen comes back on.
The only way to turn my screen off in this locked situation is to (a) wait for it to time out by itself, (b) unlock the device and then switch it off, or (c) very carefully press the button without allowing my hand to go near the prox sensor.
Can you think of some clever way to stop this from happening e.g. only have the service active when the phone is locked with the screen off?
:)
Well the phone is still locked while you try to shut the screen off, right? And this service's soul purpose is that it keeps the screen from unwanted touches till the moment you unlock it, right? I'm not responsible for the placement of the proximity sensor on device. And unfortunately I cannot implement a mental feature which would find out what you would like to do ;).
I also do suffer from which you mentioned here. But I'm getting used to it.
Of course while using it, I will try to evaluate and find out how I could improve this service. But honestly, these things should be done by Google, HTC and all the factories since this shouldn't be an application but a low-level feature of touch-screen devices...
 
Of course not. This service activates proximity
It's very complicated what you're asking for. There would be many checks, what's really going on at the moment. Just imagine. While in a conversation, the device would also lock itself. That wouldn't be the expected behavior. But I don't say that I won't think about it. I'll evaluate it while using it.

ok. I'll try to explain what I would like to reach with this tool :)

1. proximity sensor is checked only when there is headset connected to the phone and screen is ON
2. in case there is something near the sensor - screen turns off and lock the phone. in case there is nothing - no action is done.

when there is no headset connected, sensor is not checked, screen is not disabled when something is near proximity sensor. during conversation (without headset) it is held properly by android itself (and phone is not going to lock). the problem we all have with HTC sense phones is that after conversation with BT headset screens remains ON and phone is unlocked in the pocket (even if it was locked before starting conversation with BT headset)

there are only 3 checks:
1 headset connected (yes- proceed, no - do nothing)
2 screen is on (yes - proceed, no - do nothing)
3 check proximity sensor (something is there - proceed, no - do nothing)
- action: lock phone (as it's in the pocket)
 
the problem we all have with HTC sense phones is that after conversation with BT headset screens remains ON and phone is unlocked in the pocket (even if it was locked before starting conversation with BT headset)
No-no-no, not just that! The incoming call lock screen (< Sense3.0) is easily handled unporposely. En event notification also lights up the screen and you can accidentally abandon it without even knowing about it. All these happen while the device is LOCKED. I've been facing with these problems for more than a year now. You can browse through the previous comments...
You can solve the automatic screen locking by several other tools. This one won't do that, sorry if this disappoints you, it wasn't meant that way...
But to return to your particular problem about finishing bluetooth phone calls, even if your device won't be locked after a call, it cannot be touch unpurposely. After the specified timeout, it will lock itself automatically as specified at the system level. Why is this not enough for you?
 
there are only 3 checks:
1 headset connected (yes- proceed, no - do nothing)
2 screen is on (yes - proceed, no - do nothing)
3 check proximity sensor (something is there - proceed, no - do nothing)
- action: lock phone (as it's in the pocket)
:)
This service never checks proximity sensor state as I've pointed out several times. Android does that the same way as it's done while making calls. This service enables that feature when the situation requires so.
I made the source also available. You can change or have one changed whatever you want.
 
I rely on this tool a lot, as my power button is nearly broken and I don't use it.. I set "Event controlled" option and also screen timeout in display settings to 30s. So I just put it in a pocket after use, it autolocks itself shortly, and then the proximity service switches off the screen

However, if I install one of those numerous widgets on the market to switch off the screen, they also lock the phone in such a way that the proximity service can't bring it back.. In fact, it is the same as if I switch off the screen with the usual power button -- the service doesn't bring it back then

Do you know any solution to this by chance?..

HTC Desire S, Android 2.3.3 + Sense 2.1
 
However, if I install one of those numerous widgets on the market to switch off the screen, they also lock the phone in such a way that the proximity service can't bring it back.. In fact, it is the same as if I switch off the screen with the usual power button -- the service doesn't bring it back then
Do you know any solution to this by chance?..
HTC Desire S, Android 2.3.3 + Sense 2.1
:-)
This shows me how different we all are.
Honestly, since my power button is okay, I have no problem with this. I even find this feature quite okay that I can't wake the device without pressing a button. I was a little more pre-cautious with this than you because my power button can only switch the device to stand-by, I cannot wake it up with that. I wake it with the trackpad. I don't know if the Desire S has any of that.
Android 2.2 functioned that way that this tool woke the device always up, even if you sent it to sleep with the power button. 2.3.3 has altered this behaviour to this. I like it more but unfortunately I can't do anything to change this.
 
Here's a strange thing... I am running with the CyanogenMod 7.1 ROM on my Desire, and I have Event Controlled set in Proximity Service. Here's the sequence of events:

1 Turn the screen off with power button.
2 Wake the screen (with power button of track pad), but take no further action
3 Wait for the screen to turn off via timeout.
4 Put finger over proximity sensor (to simulate putting in pocket)
5 Remove finger - the screen wakes up! This is without pressing any buttons or any other action.

Note that this does not happen if I manually switch the screen off at step 3. Note also that the problem does still occur if you unlock the screen at step 2, as long as you then wait for the screen to timeout and lock again i.e. do not switch it off manually.

In summary the problem seems to be related to the screen timing out while Event Controlled is enabled. It is as if, when the screen has timed out, the service thinks that when the proximity sensor is deactivated (as at step 5) it must wake up the screen irrespective of whether it was previously awake.

I've no idea whether this problem only occurs when used with CyanogenMod, or with stock and other custom ROMs as well.

Is there something hat can be done about this?
 
Here's a strange thing... I am running with the CyanogenMod 7.1 ROM on my Desire, and I have Event Controlled set in Proximity Service. Here's the sequence of events:

1 Turn the screen off with power button.
2 Wake the screen (with power button of track pad), but take no further action
3 Wait for the screen to turn off via timeout.
4 Put finger over proximity sensor (to simulate putting in pocket)
5 Remove finger - the screen wakes up! This is without pressing any buttons or any other action.

Note that this does not happen if I manually switch the screen off at step 3. Note also that the problem does still occur if you unlock the screen at step 2, as long as you then wait for the screen to timeout and lock again i.e. do not switch it off manually.

In summary the problem seems to be related to the screen timing out while Event Controlled is enabled. It is as if, when the screen has timed out, the service thinks that when the proximity sensor is deactivated (as at step 5) it must wake up the screen irrespective of whether it was previously awake.

I've no idea whether this problem only occurs when used with CyanogenMod, or with stock and other custom ROMs as well.

Is there something hat can be done about this?

It has nothing to do with this service. It has rather to do with Gingerbread. I have a stock-like ROM and the same phenomenon. I haven't bothered with it yet but I might be able to do something against it, I'm not sure. Some kind of a workaround.
I repeat. It has nothing to do with this service. I always have to point out that this tool never locks or wakes the screen. Lock timeout locks the screen, proximity sensing blanks the screen. The latter is part of Android. This service only activates it based on several conditions.
In the previous post I've been writing about how I like in Gingerbread that when I press the power (sleep) button, the screen doesn't come back by getting near to and then far from the device. In Froyo the screen always came back, even if you previously sent the device to sleep with the power button. There must be some difference between the power button and the lock timeout locking method. I haven't checked the AOSP sources. Yet...
 
I want to use it, but wait until you have the optional features to the program itself did not include the screen. To work only for off-line. Wait?
 
My HTC Incredible S is in a flip leather case so I'm using the proximity sensor to turn on and off the screen by just flipping the cover cos the power button on the phone is rather hard to press.

So I'm using it without the events mode and it works great. But I just noticed that when the cover/flap is completely closed over the phone, the screen is turned on. when I raise the cover slightly, then the screen goes blank. However when I used my finger to cover the proximity sensor, it works fine.

Could my flip cover be reflecting light to trigger the sensor when closed? I downloaded the source code wondering if I could turn on debug messages which I can then observe with logcat. Is there just a flag, or do I have to add in the debug statements?
 
Try downloading AndroSensor from the market. That might give you some clues as to how the prox sensor is behaving in different situations.
 
Try downloading AndroSensor from the market. That might give you some clues as to how the prox sensor is behaving in different situations.

Ok I'll go try that. I've did some experimenting and discovered that the screen is turned on when the case touches the screen!

Experiment 1: I use my finger to hover over the light sensor, the screen turns off. I continued lowering my finger until it touched the screen. It remained off.

Experiment 2: I use a folded piece of black duct tape, and hover it over the sensor. The screen turns off. I continued lowering the tape, and when it touches the screen, it turns on!

So there's something funny going on here.
 
Just as nikenike asked... I'd like this up to be able to unlock the screen while in event controlled mode with Gingerbread 2.3.x
It works if I don't check "event controlled" box, but I don't like to keep the sensor on all the time
I'm not a developer so I don't know if it is possible, but I'd like to suggest how it could work:
1- make an icon or a widget which turns off the screen (it doesn't lock it) AND activate the proximity sensor at the same time
2- when the phone is taken out of the pocket (or you tap the sensor) the screen turns on AND proximity sensor is turned off.
This way you don't need physical keys anymore and the sensor is used only when necessary.
This solution would also prevent the screen from turning off when using it in landscape.
I always have to disable the app when I play Plants vs Zombie or I use the browser because I accidentally put my hand on the sensor

I hope it is possible :D
 
2- when the phone is taken out of the pocket (or you tap the sensor) the screen turns on AND proximity sensor is turned off.
This way you don't need physical keys anymore and the sensor is used only when necessary.
So you suggest to turn off sensing (wake-lock) when the screen comes back on. This might occur accidentally. How would you prevent that?
 
So you suggest to turn off sensing (wake-lock) when the screen comes back on. This might occur accidentally. How would you prevent that?

With a custom lockscreen.
Example: now I am using Magic Locker (I don't know if it works with other lockscreens). When the screen turns off it is automatically activated, even if the phone is not locked.
When I get the phone out of my pocket the screen switches on, but the locker prevents any accidental tap.
There should be a way to switch the sensor on again when the screen goes off again (for the timeout)... again, I don't know if it is possible, but it would be cool.

Have you ever seen the Nokia N9 (MeeGo) lock system? The lockscreen stays on as long as you keep the phone out of the pocket, showing only the time/date, then it uses the proximity sensor to turn the screen on/off if it is put in/taken out of the pocket. To unlock the phone you have to double-tap the lockscreen.
I think it's awesome :D
 
Have you ever seen the Nokia N9 (MeeGo) lock system? The lockscreen stays on as long as you keep the phone out of the pocket, showing only the time/date, then it uses the proximity sensor to turn the screen on/off if it is put in/taken out of the pocket. To unlock the phone you have to double-tap the lockscreen.
I think it's awesome :D
Excuse me, but this utlility works the same way as you wrote. You just need to enable the event driven feature.
 
Excuse me, but this utlility works the same way as you wrote. You just need to enable the event driven feature.

Actually I have to use a physical key to unlock the phone, because (as you explained before) the app can't wake the locked phone in android 2.3
 
Status
Not open for further replies.
Back
Top Bottom