当前位置: 首页>>代码示例>>Java>>正文


Java LocationManager.requestSingleUpdate方法代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:24,代码来源:GeolocationTracker.java

示例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.");
    }
}
 
开发者ID:shivam301296,项目名称:True-Weather,代码行数:11,代码来源:LocationDialog.java


注:本文中的android.location.LocationManager.requestSingleUpdate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。