android.location.LocationManager.requestSingleUpdate()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(346)

本文整理了Java中android.location.LocationManager.requestSingleUpdate()方法的一些代码示例,展示了LocationManager.requestSingleUpdate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocationManager.requestSingleUpdate()方法的具体详情如下:
包路径:android.location.LocationManager
类名称:LocationManager
方法名:requestSingleUpdate

LocationManager.requestSingleUpdate介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
locationManager.requestSingleUpdate(criteria, new LocationListener() {
  @Override
  public void onLocationChanged(Location location) {
  Criteria criteria = new Criteria();
  criteria.setAccuracy(Criteria.ACCURACY_FINE);
  locationManager.requestSingleUpdate(criteria, new LocationListener() {
    @Override
    public void onLocationChanged(Location location) {

代码示例来源:origin: stackoverflow.com

locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, locationListenerGps, Looper.myLooper());
locationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, locationListenerNetwork, Looper.myLooper());

代码示例来源:origin: WangDaYeeeeee/GeometricWeather

@Override
  public void run() {
    if (locationManager != null) {
      locationManager.removeUpdates(listener);
      locationManager.requestSingleUpdate(provider, listener, null);
    }
  }
});

代码示例来源:origin: stackoverflow.com

LocationManager lm = getSystemService(Context.LOCATION_SERVICE);

  if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER))
  lm.requestSingleUpdate(LocationManager.GPS_PROVIDER, this, null);
else if (lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
  lm.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, this, null);
else {
  try {
    throw (new Exception("No location provider is available!"));
  } catch (Exception e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: qqq3/good-weather

public void gpsRequestLocation() {
  if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
    Looper locationLooper = Looper.myLooper();
    locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, mLocationListener, locationLooper);
    final Handler locationHandler = new Handler(locationLooper);
    locationHandler.postDelayed(new Runnable() {
      @Override
      public void run() {
        locationManager.removeUpdates(mLocationListener);
        if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
          Location lastLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
          if (lastLocation != null) {
            mLocationListener.onLocationChanged(lastLocation);
          } else {
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocationListener);
          }
        }
      }
    }, LOCATION_TIMEOUT_IN_MS);
  }
}

代码示例来源:origin: stackoverflow.com

LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER))    
          manager.requestSingleUpdate(LocationManager.GPS_PROVIDER, mLocationListener, null);

代码示例来源:origin: qqq3/good-weather

public void networkRequestLocation() {
  if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
    Looper locationLooper = Looper.myLooper();
    locationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, mLocationListener, locationLooper);
    final Handler locationHandler = new Handler(locationLooper);
    locationHandler.postDelayed(new Runnable() {
      @Override
      public void run() {
        locationManager.removeUpdates(mLocationListener);
        if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
          Location lastNetworkLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
          Location lastGpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
          if ((lastGpsLocation == null) && (lastNetworkLocation != null)) {
            mLocationListener.onLocationChanged(lastNetworkLocation);
          } else if ((lastGpsLocation != null) && (lastNetworkLocation == null)) {
            mLocationListener.onLocationChanged(lastGpsLocation);
          } else {
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, mLocationListener);
          }
        }
      }
    }, LOCATION_TIMEOUT_IN_MS);
  }
}

代码示例来源:origin: qqq3/good-weather

private void detectLocation() {
  if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
    final Looper locationLooper = Looper.myLooper();
    locationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, this, locationLooper);
    final LocationListener locationListener = this;
    final Handler locationHandler = new Handler(locationLooper);

代码示例来源:origin: tranquvis/SimpleSmsRemote

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_test);
  Criteria criteria = new Criteria();
  criteria.setAccuracy(Criteria.ACCURACY_COARSE);
  LocationManager locationManager = (LocationManager)
      this.getSystemService(Context.LOCATION_SERVICE);
  startTime = System.currentTimeMillis();
  try {
    locationManager.requestSingleUpdate(criteria, this, null);
  } catch (SecurityException e) {
    Log.e(TAG, "permission not granted");
  }
}

代码示例来源:origin: stackoverflow.com

public void getMyLocation(Activity activity) {
  int requestPermissionsCode = 50;
  LocationManager locationManager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
  if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, requestPermissionsCode);
    return;
  }
  Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  if (location != null) {
    LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
    if (locationListener != null)
      locationListener.onLocationFound(latLng);
    return;
  }

  locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, new SingleUpdateListener(), null);

}

代码示例来源:origin: tranquvis/SimpleSmsRemote

locationManager.requestSingleUpdate(criteria, locationListener, Looper.getMainLooper());

代码示例来源:origin: stackoverflow.com

private void getLocation() {
  LocationManager  locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  Criteria criteria = new Criteria();
  provider = locationManager.getBestProvider(criteria, false);
  Location location = locationManager.getLastKnownLocation(provider);
  if (location != null) {
    onLocationChanged(location);
  } else {
    locationManager.requestSingleUpdate(provider, myLocationListener, null);
  }
}

代码示例来源:origin: thuryn/your-local-weather

private boolean gpsRequestLocation() {
  boolean isGPSEnabled = AppPreference.isGpsEnabledByPreferences(getBaseContext()) &&
      locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)
      && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
  if (isGPSEnabled && ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
    Looper locationLooper = Looper.myLooper();
    appendLog(getBaseContext(), TAG, "get location from GPS");
    timerHandlerGpsLocation.postDelayed(timerRunnableGpsLocation, GPS_LOCATION_TIMEOUT_IN_MS);
    locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, gpsLocationListener, locationLooper);
    startRefreshRotation("gpsRequestLocation", 3);
    return true;
  } else {
    return false;
  }
}

代码示例来源:origin: vitas/beaconloc

locationManager.requestSingleUpdate(criteria, pendingIntent);

代码示例来源:origin: stackoverflow.com

myLocationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER,
  this, null);

代码示例来源:origin: denzilferreira/aware-client

locationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, Locations.this, getMainLooper());
lastNetwork = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

代码示例来源:origin: sylvek/itracing2

locationManager.requestSingleUpdate(criteria, pendingIntent);

代码示例来源:origin: derry/delion

/**
 * 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);
    }
  }
}

代码示例来源:origin: thuryn/your-local-weather

startRefreshRotation("detectLocation", 3);
final Looper locationLooper = Looper.myLooper();
locationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, this, locationLooper);
final LocationListener locationListener = this;
final Handler locationHandler = new Handler(locationLooper);

代码示例来源:origin: denzilferreira/aware-client

locationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, Locations.this, getMainLooper());
lastNetwork = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

相关文章