Can someone provide an example of using a proximity sensor? I tried to use it in the same way as other sensors, but it does not work.
This is the code snippet I used:
final SensorManager mSensorManager;
final Sensor mproximity;
mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
mproximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
mSensorManager.registerListener(new SensorListener(){
public void onAccuracyChanged(int arg0, int arg1) {
Toast.makeText(test.this,"proximity sensor accu ", Toast.LENGTH_SHORT).show();
}
public void onSensorChanged(int arg0, float[] arg1) {
Toast.makeText(test.this,"proximity sensor ", Toast.LENGTH_SHORT).show();
}
}, Sensor.TYPE_PROXIMITY, 1);
Please tell me where I am wrong.
source
share