Use proximity sensor to disable screen while in pocketSupport


Thread Status:
Not open for further replies.

Last Updated:

  1. obones

    obones Member This Topic's Starter

    Joined:
    Jun 7, 2010
    Messages:
    15
    Likes Received:
    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
     

    Advertisement
    Juicerldx and yorkmolko like this.
  2. paulcooper

    paulcooper Well-Known Member

    Joined:
    Apr 19, 2010
    Messages:
    266
    Likes Received:
    9
    An excellent idea, mine has done alsorts of things in my pocket!
     
  3. copas2

    copas2 Well-Known Member

    Joined:
    May 28, 2010
    Messages:
    71
    Likes Received:
    23
    Yes, I've come to this point myself. I think I'll wait 'till 2.2 and see if there's some changes. And after that I'll implement is myself. Why not...
     
  4. obones

    obones Member This Topic's Starter

    Joined:
    Jun 7, 2010
    Messages:
    15
    Likes Received:
    6
    Well, I created an application that respond to the proximity sensor events, but I can't seem to be able to disable the screen like the call application does.

    There might be some undocumented methods but I would very much prefer a supported API.

    Does anyone have any idea?
     
  5. SUroot

    SUroot Well-Known Member Developer

    Joined:
    May 25, 2010
    Messages:
    23,925
    Likes Received:
    5,304
    Why does it do this? Ive noticed my screen is unlocked in my pocket on occasion. I thought is was somehow swiping the screen on my leg as I took it out..

    :(
     
  6. staz1000

    staz1000 Well-Known Member

    Joined:
    Apr 9, 2010
    Messages:
    229
    Likes Received:
    16
    You should try a case/fonesox, I never have this problem.
     
  7. SUroot

    SUroot Well-Known Member Developer

    Joined:
    May 25, 2010
    Messages:
    23,925
    Likes Received:
    5,304
    It happens rarely to me. ..and i'd rather call someone from my pocket than have a fonesox ;)
     
  8. copas2

    copas2 Well-Known Member

    Joined:
    May 28, 2010
    Messages:
    71
    Likes Received:
    23
    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.
     
    mjpartyboy and yorkmolko like this.
  9. scudd

    scudd Member

    Joined:
    May 17, 2010
    Messages:
    12
    Likes Received:
    0
    This works great. I hope you can keep up support for it but it works flawlessly. Thanks



    Sent from my HTC Desire
     
  10. copas2

    copas2 Well-Known Member

    Joined:
    May 28, 2010
    Messages:
    71
    Likes Received:
    23
    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
     
    Mushhushshu likes this.
  11. Mushhushshu

    Mushhushshu Well-Known Member

    Joined:
    Jun 13, 2010
    Messages:
    119
    Likes Received:
    24
    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
     
  12. staz1000

    staz1000 Well-Known Member

    Joined:
    Apr 9, 2010
    Messages:
    229
    Likes Received:
    16
    That's a great little app but when the phone is locked the screen goes to the unlock screen without pressing the top button.

    EDIT: What he said /\
     
  13. bjrmd

    bjrmd Member

    Joined:
    Jun 13, 2010
    Messages:
    6
    Likes Received:
    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.
     
  14. obones

    obones Member This Topic's Starter

    Joined:
    Jun 7, 2010
    Messages:
    15
    Likes Received:
    6
    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?
     
  15. obones

    obones Member This Topic's Starter

    Joined:
    Jun 7, 2010
    Messages:
    15
    Likes Received:
    6
    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?
     
  16. copas2

    copas2 Well-Known Member

    Joined:
    May 28, 2010
    Messages:
    71
    Likes Received:
    23
    :)
    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.
     
  17. copas2

    copas2 Well-Known Member

    Joined:
    May 28, 2010
    Messages:
    71
    Likes Received:
    23
    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.
     
  18. copas2

    copas2 Well-Known Member

    Joined:
    May 28, 2010
    Messages:
    71
    Likes Received:
    23
    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 :)
     
  19. copas2

    copas2 Well-Known Member

    Joined:
    May 28, 2010
    Messages:
    71
    Likes Received:
    23
    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 :)
     
  20. bjrmd

    bjrmd Member

    Joined:
    Jun 13, 2010
    Messages:
    6
    Likes Received:
    0

    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.
     
  21. copas2

    copas2 Well-Known Member

    Joined:
    May 28, 2010
    Messages:
    71
    Likes Received:
    23
    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.
     
  22. haris9

    haris9 Well-Known Member

    Joined:
    May 30, 2010
    Messages:
    52
    Likes Received:
    5
    Use proximity sensor to disable screen while in pocket




    Use screen pattern option of desire, hope your problem will be solved.:)
     
  23. copas2

    copas2 Well-Known Member

    Joined:
    May 28, 2010
    Messages:
    71
    Likes Received:
    23
    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.
     
  24. saccerzd

    saccerzd New Member

    Joined:
    Jun 12, 2010
    Messages:
    3
    Likes Received:
    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?
     
  25. copas2

    copas2 Well-Known Member

    Joined:
    May 28, 2010
    Messages:
    71
    Likes Received:
    23
    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.
     
    saccerzd likes this.
Thread Status:
Not open for further replies.

Share This Page

Loading...