• 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.

obones

Newbie
Jun 7, 2010
15
6
Hello,

As many users, I've experienced the problem that when the desire is in my pocket and I receive a notification, the screen gets accidentally unlocked and the phone starts doing things that I don't want it to do.
I know I can add an unlock pattern so that it won't unlock as easily but this is at the expense of me having to enter it even in situations I would not have needed it.
So I thought that maybe we could use the proximity sensor to tell the phone to never unlock the screen if an object is close to the phone.
Quickly looking at the android docs, it seems that the support for this is in the SDK, but I was wondering if anyone had created an application that does this.
If time permits, I might even have a look at doing it myself, but as I'm very new to Android development, it will take me quite a long time to get to a usable state, hence my question about an existing app that does this.

Regards
Olivier
 
I made a 5-10 line code of service which needs to be started every time you bike :) and stopped when resuming normal usage (not anymore, see later post). It would be annoying to have it always on.
Starting it toggles the service on and off. The task is very simple. While the service is active it turns the screen off every time when something's near and turns it back on when far. It means the screen will (should) be turned off (not locked) by it while in pocket. The very same like while in a call.
The service consumes nothing. It neither does poll nor run anything. When turned on, it just "aquires" a PowerManager.WakeLock (PROXIMITY_SCREEN_OFF_WAKE_LOCK (32)). Turning it off, that WakeLock will be released. The system does the actual screen toggling. The apk was packaged against and run on Android version 2.1. I don't see why it shouldn't run on 2.2 or even earlier releases. The device is an HTC Desire. It should run on any other device which has a proximity sensor built in and implemented towards Android. Task Killer users should check their settings and append this to the exception list of course.

The service can be found here: (old link removed)
http://code.google.com/p/proximitytoolextension/downloads/list

You use it of course on your own responsibility :).

Since I don't really have enough time to dive into the SDK of Android in the moment, for a week or two I just can't make any progress with this. But I'm thinking about implementing some improvements. It might be useful if the screen would only go off when attaching headphones. I'm open to ideas of course.
 
Upvote 0
Okay, I implemented the change now. General proximity sensing and screen toggling only active when headset plugged in. Headset presence is automatic of course (using BroadcastReceiver events). No further battery usage. You can still have the general screen toggling version if you use this file name in the link: ProximityTool.general.apk
 
  • Like
Reactions: Mushhushshu
Upvote 0
I have been looking for an app like this since I got my Evo. We had a few great proximity sensor screen toggles for windows mobile on my old HD2 Leo. But your app is not working on the EVO--it does flash the start and stop messages. Any ideas? BTW--if this can be fixed up a bit I am sure you could made a few dollars on the market--nothing else out there right now.
 
Upvote 0
Another thing that came to me, while re-reading the documentation here:

PowerManager | Android Developers

It says that the battery life will be greatly affected by the use of these APIs. So, if I understand things correctly, using the WakeLock, even with an undocumented flag will actually drain the battery and reduce the time between charges.

Am I correct?

:)
Well, these lines just mean a lot and they mean nothing either. It should depend on how you use it, I suppose. If you use WakeLock for making sure the screen is on full brightness, etc then it will drain the battery of course. But here, WakeLock is used for screen off/on toggling, completely managed by the system itself. If the hardware/software interconnects via IRQs then it drains nothing while there's no change in the state of the proximity sensor. If it uses polling (which would be stupid) it would drain the battery.
But, this service aquires WakeLock only for the time the headset is connected to the device. It shouldn't just turn off the screen whenever is wants (eg. when typing, etc). But when using headsets it's more likely that the phone is not in your hand but somewhere else.
 
Upvote 0
Thanks for this.
I can't find PROXIMITY_SCREEN_OFF_WAKE_LOCK in the documentation, which leads me to believe it is not a reliable value to use.
Am I correct here?
Because it's hidden at the moment? This is reliable now because it works. The phone application uses it (value of 32). They sure have their reasons why this hasn't been put in the documentation. But it doesn't mean it's more unreliable than anything else. If Google changes any of the values which are right now in the code/documentation they won't be reliable anymore, right? :) Everything is always for the time being. New Android version, new approach.
 
Upvote 0
I have been looking for an app like this since I got my Evo. We had a few great proximity sensor screen toggles for windows mobile on my old HD2 Leo. But your app is not working on the EVO--it does flash the start and stop messages. Any ideas? BTW--if this can be fixed up a bit I am sure you could made a few dollars on the market--nothing else out there right now.
Well, it should only work while headset is attached. And I think it needs Android 2.1 at least. I have a Desire, nothing else to experiment on. Not that I want though :)
 
Upvote 0
Awesome little app, just what I was looking for. Using the version that works with/without headphones I have noticed that it turns the screen on when my desire is locked with the screen off if I place my hand over the proxy sensor then move it away - any chance this could be fixed if you have time? Still a handy app in the meantime though so thanks :D
I'll check it out if there's something to do but it doesn't really bother me. Just turn it off when not using it and back on when you need it.
When screen locked it stays locked so there should be no problem with it. If it's in your pocket the screen will never be lit. Goal achieved. But the newer "version" with the headset sensor is more useful.
Someone mentioned here making bucks. This here isn't really worth a cent so I just give it away but if I'd like to offer free app on the market I'd still have to pay $25. Won't do that :)
 
Upvote 0
Well, it should only work while headset is attached. And I think it needs Android 2.1 at least. I have a Desire, nothing else to experiment on. Not that I want though :)


It does work! I was using the headset version, without a headset. Installed the regular version and its fine--thanks. It does cause the screen to go on and off when just sitting there. Maybe the sensor threshold can be adjusted.

Great effort. I was told by some other locking app developer that because of the android code structure this was not possible.
 
Upvote 0
There's nothing you can adjust here. I think that Google should implement this as a standard feature. I mean, while the device is in pocket or some stupid bag :)-) the screen should be turned off.

Some other problem: a snooze button appears on the locked screen when calendar event alerts. That snooze button can easily be pressed by the leg when in pocket. Who thought at Google that it would be appropriate to place a simple press button on the lock-screen?? Even the calls can only be taken or rejected by sliding something. This way it's easy to miss a reminder.

So as an additional recommendation, the proximity sensor should always turn off the screen when the phone's in screen-locked state. Remember: this, by itself won't be sufficient, since when you take a call while screen is locked, after hanging up, the screen gets unlocked for the screen timeout period. But if the proximity sensor turns off the screen, this particular after-call screen-unlock problem won't be an issue anymore. It's still very useful when not in pocket.
With this approach there will still be a problem. While in pocket, with the help of the proximity sensor, the screen can stay off. But when it's not, the screen going off and on while eg. typing will be the problem. To work around this, I think that when coming out of proximity, this feature should just be turned off. The feature should then be turned on again when manually locking the screen or automatically after the screen lock timeout.
 
Upvote 0
Use screen pattern option of desire, hope your problem will be solved.:)
I used it and I'm still using it. But it can accidentally lock me out. Plus there's an emergency button which will immediately be pressed after a call. Plus when a calendar event fires, there's a snooze button. Plus when I constantly press the device unintended, the screen's always on, eating my battery. This all BECAUSE the lock pattern comes AFTER the lock screen. ;)
I appreciate any constructive comment but... Please believe that I'm (we're) through everything which could be configured or set up before sitting down to implement something even this simple.
I'm still convinced that a touch-screen device needs to be prepared for situations where screen touches are not appropriate and even troublesome or awkward. This is an approach which builds from currently available stuff.
 
Upvote 0
Sorry if this is a stupid question, but what is the proximity sensor actually used for?

Obviously, it detects how close something is to the phone - but why? The touchscreen only picks up actual touches, doesn't it? So what does the sensor do on top of that? Is it for games? Is it the blue dot in the top left corner (very faint)?

Thanks - I'm very curious about it!

edit: I found a review which said it was used for "auto turn-off" - does this mean it turns off if it detects something mashing the screen, like a pocket for example?
 
Upvote 0
wow...
Touch screens are very sensitive. The soft buttons don't need to be pressed so if a skin alike thing's near enough, the device reacts. This won't happen on a physical button device. That's the reason why a touch screen device needs a different approach. This is the part where the proximity sensor steps in. It helps to prevent unwanted touches on the screen. A developer should know when the user has no intention to press on the screen. It's quite logical that when something covers the screen (face, pocket, etc), nobody wants to press anything. The only exceptions are the intentional touches. I think if there were two separated sensors in some distance from each other, it could help detect that a relatively large (face, etc) or small (finger) object is nearby. It could then be activated all the time.
 
  • Like
Reactions: saccerzd
Upvote 0
Status
Not open for further replies.

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones