私のアクティビティでは、GPS と WIFI の両方の位置情報サービスがオフになっているかどうかを確認しています。
両方がオフの場合、位置情報サービスの意図がトリガーされます。ただし、戻るボタンを押すと、ホーム画面ではなくアクティビティに戻ることができません。したがって、画面は場所の設定ページでスタックします。
FragmentActivity を拡張し、SupportMapFragment を使用していることに注意してください。
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
if (status != ConnectionResult.SUCCESS)
{ // Google Play Services are not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this,requestCode);
dialog.show();
} else
{
fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = fm.getMap();
googleMap.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if(locationManager != null)
{
gpsIsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
networkIsEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if(gpsIsEnabled==false && networkIsEnabled==false)
{
Log.i("code","both wifi and gps off.");
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, 1);
}
else
{
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
location = locationManager.getLastKnownLocation(provider);
if (location != null)
{
onLocationChanged(location);
}
locationManager.requestLocationUpdates(provider, 20000, 0, this);
}
}
else
{
Log.i("app","null.");
}