title: Proximity Sensor in Android does not respond
body: <p>I am trying to build a simple Android application which updates the text of a textview when the proximity sensor values change. However the textview values remain the same despite bringing an object close to the sensor.</p>
  
  <p>Here is my MainActivity.java code</p>
  
  <pre><code>import android.hardware.Sensor;
  import android.hardware.SensorEvent;
  import android.hardware.SensorEventListener;
  import android.hardware.SensorManager;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.widget.TextView;
  
  public class MainActivity extends AppCompatActivity implements SensorEventListener{
  
  
  
      private SensorManager mSensorManager;
      private Sensor mProximity;
      TextView textView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  // Get an instance of the sensor service, and use that to get an instance of
          // a particular sensor.
          mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
          mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
          mSensorManager.registerListener(this, mProximity, SensorManager.SENSOR_DELAY_NORMAL);
          textView = (TextView) findViewById(R.id.newtext);
  
      }
  
  
      public final void onAccuracyChanged(Sensor sensor, int accuracy) {
          // Do something here if sensor accuracy changes.
      }
  
  
      public final void onSensorChanged(SensorEvent event) {
          float distance = event.values[0];
          textView.setText(""+event.values[0]);
          if (distance&lt;3){
              textView.setText("near"+distance);
          }
          // Do something with this sensor data.
      }
  
      @Override
      protected void onResume() {
          // Register a listener for the sensor.
          super.onResume();
          mSensorManager.registerListener(this, mProximity, SensorManager.SENSOR_DELAY_NORMAL);
      }
  
      @Override
      protected void onPause() {
          // Be sure to unregister the sensor when the activity pauses.
          super.onPause();
          mSensorManager.unregisterListener(this);
      }
  }
  </code></pre>
  
  <p>Here is my XML code:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/activity_main"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:orientation="vertical"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context="com.example.suzancruz.senapp.MainActivity"&gt;
  
      &lt;TextView
          android:layout_width="200dp"
          android:layout_height="200dp"
          android:id="@+id/newtext"
          android:text="hjkhjk"
          /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>