我还有一个关于基本 Android 编程的问题:
如何访问 GPS 来获取运行应用程序的手机的当前位置?检索信息需要多长时间?
在这种情况下,GPS 可能被禁用,如何再次启用/禁用它。
必须在 andorid 清单中授予哪些权限?
问候并感谢您的回答,
波斯克伦
一些答案:
使用权:
看位置管理器 http://developer.android.com/reference/android/location/LocationManager.html and 位置监听器 http://developer.android.com/reference/android/location/LocationListener.html.
权限:android.permission.ACCESS_FINE_LOCATION
Demo:
public class GPSLocationManager implements LocationObservable {
private static final long INTERVAL = 10*1000;
private LocationManager locationManager;
public GPSLocationManager(LocationManager locationManager) {
this.locationManager = locationManager;
}
public void requestLocationUpdates(LocationListener locationListener) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
INTERVAL,
0, locationListener);
}
public void removeUpdates(LocationListener locationListener) {
locationManager.removeUpdates(locationListener);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)