I am doing one application using proximity sensor in android. when sensor changed it should lock the phone and when phone is locked using same sensor it should unlock a phone. To lock a phone am using double tap mechanisam. for lock using only a single tap. my code is like below:
@Override
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
if(event.sensor.getType()==Sensor.TYPE_PROXIMITY){
if(curTime2 - curTime1 < 1000)
{
Tap++;
if(Tap==2 ) //&& (curTime2 - curTime1)==100000)
{
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
mDeviceAdminSample = new ComponentName(Controller.this,
LockScreenActivity.class);
active = mDPM.isAdminActive(mDeviceAdminSample);
if(active){
mDPM.lockNow();
flagLock = true;
}
Tap=0;
// unlock
if(flagLock == false){
mKeyGuardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
mLock = mKeyGuardManager.newKeyguardLock("activity_classname");
mLock.disableKeyguard();
}
}
The unlock code is working on first tap only. I need to it should execute after the phone is locked but it is not working. How to do this? Thx in advance