title: current location (latitude, longitude and accuracy) working on my phone android 8 _level 27_ but not working on my tablet with android 5.1_level 22_
body: <p>My android app have some input fields that are automatically filled to get the current location : longitude,latitude .. and it just works fine on my phone with android 8 : level 27 but doesn't work on tablets with android 5.1 or 6 resp : level 22 and 23. I actually don't know the cause of the problem. Please help if you have an idea !
  This is my code :</p>
  <pre><code>import android.Manifest;
  import android.annotation.SuppressLint;
  import android.content.Context;
  import android.content.pm.PackageManager;
  import android.location.Address;
  import android.location.Geocoder;
  import android.location.Location;
  import android.location.LocationListener;
  import android.location.LocationManager;
  import android.os.Build;
  import android.support.annotation.NonNull;
  import android.support.v4.app.ActivityCompat;
  import android.support.v4.content.ContextCompat;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.widget.TextView;
  
  import java.io.IOException;
  import java.util.List;
  import java.util.Locale;
  
  public class MainActivity extends AppCompatActivity {
  
  LocationManager locationManager;
  LocationListener locationListener;
  TextView longitude;
  TextView latitude;
  TextView accuracy;
  TextView altitude;
  TextView address;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      longitude=findViewById(R.id.longitude_text);
      latitude=findViewById(R.id.latitude_text);
      accuracy=findViewById(R.id.accuracy_text);
      altitude=findViewById(R.id.altitude_text);
      address=findViewById(R.id.address_text);
  
      locationManager= (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
      locationListener= new LocationListener() {
          @Override
          public void onLocationChanged(Location location) {
  
             updateLocationInfo(location);
  
          }
  
          @Override
          public void onStatusChanged(String provider, int status, Bundle extras) {
  
          }
  
          @Override
          public void onProviderEnabled(String provider) {
  
          }
  
          @Override
          public void onProviderDisabled(String provider) {
  
          }
      };
  
  
      if(Build.VERSION.SDK_INT&lt;23)
      {
         startListening();
      }
      else {
          if(ContextCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION)!=PackageManager.PERMISSION_GRANTED)
          {
              ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},1);
          }
          else
          {
              locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);
              Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
              if(location!=null)
              {
                  updateLocationInfo(location);
              }
          }
      }
  
  
  
  }
  
  
  @Override
  public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
      super.onRequestPermissionsResult(requestCode, permissions, grantResults);
      if (grantResults.length&gt;0&amp;&amp; grantResults[0]==PackageManager.PERMISSION_GRANTED)
      {
            startListening();
      }
  }
  
  @SuppressLint(&quot;MissingPermission&quot;)
  public void startListening ()
  {
      if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)==PackageManager.PERMISSION_GRANTED)
      {
          locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);
      }
  }
  
  public  void updateLocationInfo(Location location)
  {   String address_str =&quot;Could not find address&quot;;
      Log.i(&quot;Location Info&quot;,location.toString());
      longitude.setText(&quot;Longitude :&quot;+String.valueOf(location.getLongitude()));
      latitude.setText(&quot;Latitude :&quot;+String.valueOf(location.getLatitude()));
      altitude.setText(&quot;Altitude :&quot;+String.valueOf(location.getAltitude()));
      accuracy.setText(&quot;Accuracy :&quot;+String.valueOf(location.getAccuracy()));
  
      Geocoder geocoder =new Geocoder( getApplicationContext(),Locale.getDefault());
      try {
          List&lt;Address&gt; listAddress =geocoder.getFromLocation(location.getLatitude(),location.getLongitude(),1);
          if (listAddress!=null&amp;&amp;listAddress.size()&gt;0)
          {   address_str=&quot;&quot;;
              Log.i(&quot;LocationAddress&quot;,listAddress.get(0).toString());
              if(listAddress.get(0).getSubThoroughfare()!=null)
              {
                  address_str +=listAddress.get(0).getSubThoroughfare()+&quot;\n&quot;;
              }
              if(listAddress.get(0).getLocality()!=null)
              {
                  address_str +=listAddress.get(0).getLocality()+&quot;\n&quot;;
              }
  
              if(listAddress.get(0).getPostalCode()!=null)
              {
                  address_str +=listAddress.get(0).getPostalCode()+&quot;\n&quot;;
              }
  
              if(listAddress.get(0).getCountryName()!=null)
              {
                  address_str +=listAddress.get(0).getCountryName()+&quot;\n&quot;;
              }
  
          }
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      address.setText(&quot;Address: \n&quot;+address_str);
  }
  }
  </code></pre>