Android デバイスでユーザーの位置を取得しようとしています。プログラムは、GPS の使用可能性をチェックします。GPSProvider が無効になっている場合、ユーザーに警告します。ユーザーが GPS を有効にしない場合は、プログラムで networkProvider をチェックします。
ネットワークプロバイダーをチェックするためのコード、
public boolean askNetworkProvider(){
if(!locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
AlertDialog builder = new AlertDialog.Builder(context)
.setMessage("Enable Network Connection")
.setTitle("Warning!")
.setCancelable(true)
.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
return;
}
} ).show();
}
if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 2000, 0, networkListener);
mlocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Log.i(LocationService.class.getName(),"Network Enable!!");
return true;
}
return false;
}
wifiとモバイル接続が無効になっているにもかかわらず、networkProviderが有効であると表示され、2番目のifステートメントを入力します。しかし、それは偽であるべきです。どうすれば修正できますか?