0

private void getDeviceInfo() {

SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

    if(sensorManager!=null)
    {
       Sensor proxySensor = SensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
        if(proxySensor!=null)
        {
            sensorManager.registerListener(this, proxySensor, SensorManager.SENSOR_DELAY_NORMAL);
        }

    }

}

public void onSensorChanged(SensorEvent event) {

    if(event.sensor.getType()==Sensor.TYPE_PROXIMITY){
        ((TextView)findViewById(R.id.tv_proximity)).setText((""+ event.values[0]));
    }

}

Please help me with this error.

I was trying to set the textview value with proximity sensor value;

mProximity is the textView that i am using in thr XML file.

  • Change `SensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY)` to `sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY)` (the only difference being the first character is lowercase) – Tim Moore Apr 23 '23 at 04:07

0 Answers0