從第一眼看到的東西讓GPS座標看起來簡單(僞):架構GPS的基於應用
private void onStart() {
res = ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION);
if (res != PackageManager.PERMISSION_GRANTED) {
requestPermissions();
} else {
startGps();
}
}
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
if (all_ok)
startGps();
}
private void startGps() {
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {...};
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}
但如何處理異步事件:
如果
locationManager.requestLocationUpdates
後什麼用戶暫停和恢復應用,1.1我應該撥打
locationManager.requestLocationUpdates
再次接收GPS數據嗎?1.2如果用戶在我的應用程序暫停時禁用GPS,用戶恢復我的應用程序後會怎麼樣?我會收到
onProviderDisabled
事件嗎?如何處理ACCESS_FINE_LOCATION權限的運行時撤銷,如果在
locationManager.requestLocationUpdates
調用後發生?撤消後會發生什麼,Android是否通過onStatusChanged
或onProviderDisabled
報告了我的問題?我聽說新的Android允許在屏幕上的幾個窗口, 如果一個窗口都屬於會發生什麼我的應用程序,另一個「系統偏好設置」,並吊銷用戶ACCESS_FINE_LOCATION沒有我的應用程序的暫停/恢復?
其實我的要求做的代碼幾乎都在通過您的鏈接,瞭解如何後處理事情的問題提供。 – user1244932