如何使用意图服务在没有互联网的情况下获取位置?

How to get location without internet using intent service?

我不想使用在后台持续 运行 的服务!实际上,在我的项目中,用户将从任何智能手机发送短信命令到 his/her 放错位置 smartphone.My 应用程序将检测到特定的 "SMS command" 并且在 return 中它将发送放错位置的手机的当前位置. 可以通过意向服务来完成吗?我他妈的很困惑......它的单次操作如何有效地执行它......?

通过使用 NETWORK_PROVIDER 获取地理位置

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
      // Called when a new location is found by the network location provider.
      makeUseOfNewLocation(location);
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {}

    public void onProviderEnabled(String provider) {}

    public void onProviderDisabled(String provider) {}
  };

// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

并在 manifest.xml

中添加此权限
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />