本文整理汇总了Java中android.location.LocationManager.requestSingleUpdate方法的典型用法代码示例。如果您正苦于以下问题:Java LocationManager.requestSingleUpdate方法的具体用法?Java LocationManager.requestSingleUpdate怎么用?Java LocationManager.requestSingleUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.location.LocationManager
的用法示例。
在下文中一共展示了LocationManager.requestSingleUpdate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: refreshLastKnownLocation
import android.location.LocationManager; //导入方法依赖的package包/类
/**
* Requests an updated location if the last known location is older than maxAge milliseconds.
*
* Note: this must be called only on the UI thread.
*/
@SuppressFBWarnings("LI_LAZY_INIT_UPDATE_STATIC")
static void refreshLastKnownLocation(Context context, long maxAge) {
ThreadUtils.assertOnUiThread();
// We're still waiting for a location update.
if (sListener != null) return;
LocationManager locationManager =
(LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location == null || getLocationAge(location) > maxAge) {
String provider = LocationManager.NETWORK_PROVIDER;
if (locationManager.isProviderEnabled(provider)) {
sListener = new SelfCancelingListener(locationManager);
locationManager.requestSingleUpdate(provider, sListener, null);
}
}
}
示例2: onPreExecute
import android.location.LocationManager; //导入方法依赖的package包/类
@Override
protected void onPreExecute() {
super.onPreExecute();
locMan = (LocationManager) context.getSystemService(LOCATION_SERVICE);
try {
locMan.requestSingleUpdate(LocationManager.GPS_PROVIDER, locListerner, null);
} catch (SecurityException e) {
showError("Permission Denied.");
}
}