Android Proximity Sensor [Unique Issue - Sensor Not Detecting Objects Already Near The Phone] -


i'm updating application based on users huge request. app turns screen on after happens , i'm integrating "pocket mode" functionality. if user has phone or device in his/her pocket detect via proximity sensor , act based on this. i'm experiencing lot of troubles..

so i'm registering sensor , usual. 1 thing point out i'm telling powermanager object register proximity_screen_off_wake_lock. means every time screen go automatically off when near detected.

powermanager.newwakelock(powermanager.proximity_screen_off_wake_lock, "proximityscreenoff"); 

basically when device on table , move finger sensor screen turns off expected.

the problem starts when activity launches , i'm holding finger on sensor (or in pocket - it's same). sensor doesn't detect near phone. if move finger little bit away screen turn on again.

is there do, desired behavior - is, turning screen off when phone in pocket?

you can manage using boolean variable.

that if near event of onsensorchanged called, n far event called.

boolean isnearcalled =false;

void onsensorchanged() {

       if(near sensitivity) {                   isnearcalled=true;       } else if(distance sensitivity && isnearcalled) {                 // stuff far screen off                 isnearcalled= false;      }  

}


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -