this example is created by Android developer example
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); final boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); if (!gpsEnabled) new EnableGpsDialogFragment().show(getFragmentManager(), "enableGpsDialog");
private void enableLocationSettings() {
Intent settingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(settingsIntent);
}
private class EnableGpsDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.enable_gps)
.setMessage(R.string.enable_gps_dialog)
.setPositiveButton(R.string.enable_gps, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
enableLocationSettings();
}
})
.create();
}
}

0 意見:
張貼留言