I wanna get the real date in my app, when user offline. How can I get this from GPS or BTS or something else?
Asked
Active
Viewed 97 times
-1
-
Check this out. (second answer, not the accepted one) https://stackoverflow.com/questions/7017069/gps-time-in-android – Pablo Santa Cruz Sep 24 '19 at 13:12
1 Answers
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