this is my code, copy and pasted from other topics about unlock an android.. i don't know why this not work ! :(
The goal is : when the proximity sensor is HI , the device unlock itself.
(more info: Using proximity sensor lock and unlock a home screen)
Sensor work fine, but the phone still locked :(
I don't have pin lock or other , i deploy on a nexus 5.
private SensorManager mSensorManager;
private Sensor ProxymitySensor ;
private ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_unlock);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
ProxymitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
mSensorManager.registerListener(this, ProxymitySensor,SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.unlock, menu);
return true;
}
@Override
public final void onSensorChanged(SensorEvent event) {
Object sensordata = event.values[0];
// Do something with this sensor data.
if (event.values[0] == event.sensor.getMaximumRange()){
PlaySound();
UnlockMe();
}
}
private void PlaySound() {
tg.startTone(ToneGenerator.TONE_PROP_BEEP);
}
private void UnlockMe(){
// try to unlock the phone
getWindow().addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
getWindow().addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);
// nothing happen :(
}
@Override
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub
}
here the complete file : http://pastebin.com/CCv2W70Y
my fone is locked , if i put my hand on it i listen the beep and nothing more :( LocgCat don't say anityng...
any idea ?