当用户离线时,我想在我的应用中获取真实日期。 如何从GPS或BTS或其他方式获取此信息?
答案 0 :(得分: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);
这里是location.getTime()
您还可以添加locationListener
来获取位置更新,因为getLastKnownLocation
可以返回null(请参见此GPS-time in Android答案)