我不想使用在后台持续运行的服务!实际上在我的项目中,用户将从任何智能手机向他/她错放的智能手机发送短信命令。我的应用程序将检测到特定的" SMS命令"作为回报,它将发送错放的移动设备的当前位置。 可以通过意向服务来完成吗?我该死的很困惑......它的单次操作如何有效地执行它??
答案 0 :(得分:0)
使用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" />