-1

I wanna get the real date in my app, when user offline. How can I get this from GPS or BTS or something else?

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30

1 Answers1

0
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_LOW);
criteria.setPowerRequirement(Criteria.POWER_LOW);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);

locationManager = (LocationManager)context.getSystemService(LOCATION_SERVICE);
provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);

And here you go with location.getTime()

You can also add locationListener to get location updates because getLastKnownLocation can return null (see this GPS-time in Android answer)

Aleksey Khokhrin
  • 166
  • 2
  • 13