title: Not getting Location on mobile data in android
body: <p>i am not able to receive any location information when mobile data is on. my code works fine when wifi is on but does not give output on mobile data</p>
  
  <p>My code :</p>
  
  <pre><code>    private void locationInit() {
      // TODO Auto-generated method stub
      locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
              0, this);
  
      statusOfGPS = locationManager
              .isProviderEnabled(LocationManager.GPS_PROVIDER);
  
      if (statusOfGPS) {
          speak = "You are in Home Page";
          tts = new TextToSpeech(this, this);
          Toast.makeText(this,"in location init", Toast.LENGTH_SHORT).show();
      } else {
          temp = 1;
          Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
          startActivityForResult(intent, 0);
      }
  
      gps = requestUpdatesFromProvider(LocationManager.GPS_PROVIDER,
              "GPS Not Supported");
      network = requestUpdatesFromProvider(LocationManager.NETWORK_PROVIDER,
              "Network Not Supported");
  
      if (gps != null &amp;&amp; network != null) {
          location = getBetterLocation(gps, network);
      } else if (gps != null) {
          location = gps;
      } else if (network != null) {
          location = network;
      }
  
      if (location != null) {
          onLocationChanged(location);
      } else {
          latitude = 0.0;
          longitude = 0.0;
          address = "Unable to get address!";
      }
  }
  
  
  @Override
  public void onLocationChanged(Location arg0) {
      // TODO Auto-generated method stub
      try {
          latitude = location.getLatitude();
          longitude = location.getLongitude();
          accuracy = location.getAccuracy();
          try {
              address = findAddress(latitude, longitude);
              tvAddress.setText(address);
  
          } catch (Exception e) {
              address = "Unable to get address";
          }
      } catch (Exception e) {
          Log.v("TEST", e.getMessage());
      }
  }
  
  private String findAddress(double l1, double l2) {
      // TODO Auto-generated method stub
      String addr, address;
      Geocoder geocoder;
      List&lt;Address&gt; addresses = null;
      geocoder = new Geocoder(this, Locale.getDefault());
      try {
          addresses = geocoder.getFromLocation(l1, l2, 1);
      } catch (IOException e1) {
          addresses = null;
      }
  
      addr = "Unable to get address";
  
      if (addresses != null) {
          address = addresses.get(0).getAddressLine(0);
          addrs = address;
          city = addresses.get(0).getAddressLine(1);
          country = addresses.get(0).getAddressLine(2);
          if (address == null)
              address = "";
          if (city == null)
              city = "";
          addr = address + " " + city + " " + country;
      }
      return addr;
  }
  
  
  private Location requestUpdatesFromProvider(final String provider,
          final String string) {
      Location location = null;
      if (locationManager.isProviderEnabled(provider)) {
          locationManager.requestLocationUpdates(provider, 1000 * 10, 10,
                  this);
          location = locationManager.getLastKnownLocation(provider);
      } else {
          Toast.makeText(this, string, Toast.LENGTH_LONG).show();
      }
      return location;
  }
  
  protected Location getBetterLocation(Location newLocation,
          Location currentBestLocation) {
      if (currentBestLocation == null) {
          return newLocation;
      }
  
      long timeDelta = newLocation.getTime() - currentBestLocation.getTime();
      boolean isSignificantlyNewer = timeDelta &gt; 1000 * 120;
      boolean isSignificantlyOlder = timeDelta &lt; -1000 * 120;
      boolean isNewer = timeDelta &gt; 0;
  
      if (isSignificantlyNewer) {
          return newLocation;
      } else if (isSignificantlyOlder) {
          return currentBestLocation;
      }
  
      int accuracyDelta = (int) (newLocation.getAccuracy() - currentBestLocation
              .getAccuracy());
      boolean isLessAccurate = accuracyDelta &gt; 0;
      boolean isMoreAccurate = accuracyDelta &lt; 0;
      boolean isSignificantlyLessAccurate = accuracyDelta &gt; 200;
  
      boolean isFromSameProvider = isSameProvider(newLocation.getProvider(),
              currentBestLocation.getProvider());
  
      if (isMoreAccurate) {
          return newLocation;
      } else if (isNewer &amp;&amp; !isLessAccurate) {
          return newLocation;
      } else if (isNewer &amp;&amp; !isSignificantlyLessAccurate
              &amp;&amp; isFromSameProvider) {
          return newLocation;
      }
      return currentBestLocation;
  }
  
  private boolean isSameProvider(String provider1, String provider2) {
      if (provider1 == null) {
          return provider2 == null;
      }
      return provider1.equals(provider2);
  }
  </code></pre>
  
  <p>i am calling the locationInit() function in onCreate and onResume .
  i have the following permissions in my manifest.</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  </code></pre>