Skip to content

Instantly share code, notes, and snippets.

@sakurabird
Created October 7, 2013 14:32
Show Gist options
  • Save sakurabird/6868981 to your computer and use it in GitHub Desktop.
Save sakurabird/6868981 to your computer and use it in GitHub Desktop.
Androidのシステム位置情報をoffにしているユーザーに設定を促すダイアログ
package xxxxx.fragment;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import xxxxx.R;
public class RequestGPSDialogFragment extends DialogFragment {
static RequestGPSDialogFragment newInstance() {
RequestGPSDialogFragment f = new RequestGPSDialogFragment();
return f;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setMessage(getActivity().getResources().getString(R.string.dialog_gps_enable))
.setPositiveButton(
getActivity().getResources().getString(R.string.dialog_gps_enable_button),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
Intent callGPSSettingIntent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(callGPSSettingIntent);
dismiss();
}
}
)
.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
dismiss();
}
}
)
.create();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment