実際のデバイスでアプリをテストしておりnull
、GPS がオンのときに位置を取得しています。ダミー座標を使用してエミュレーターでテストすると、正常に動作します。なにが問題ですか?
locationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
listener = new MyLocationListener();
viaGps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
viaNetwork = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!viaGps && !viaNetwork) {
tracking = false;
} else {
if (viaGps) {
Log.d("", "gps is on");
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}else if (viaNetwork) {
Log.d("", "network is on");
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, listener);
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
if (location == null) {
Log.d("", "location not fouond");
}