質問: androidデバイスのgpsが有効になっているかどうかを確認する方法 android cupcake(1.5)対応デバイスで、gpsを確認して有効にするにはどうすればよいですか?
回答: 最善の方法は次のようです: final locationmanager manager = (locationmanager) getsystemservice( context.location_service ); if ( !manager.isproviderenabled( locationmanager.gps_provider ) ) { buildalertmessagenogps(); } private void buildalertmessagenogps() { final alertdialog.builder builder = new alertdialog.builder(this); builder.setmessage("your gps seems to be disabled, do you want to enable it?") .setcancelable(false) .setpositivebutton("yes", new dialoginterface.onclicklistener() { public void onclick(@suppresswarnings("unused") final dialoginterface dialog, @suppresswarnings("unused") final int id) { startactivity(new intent(android.provider.settings.action_location_source_settings)); } }) .setnegativebutton("no", new dialoginterface.onclicklistener() { public void onclick(final dialoginterface dialog, @suppresswarnings("unused") final int id) { dialog.cancel(); } }); final alertdialog alert = builder.create(); alert.show(); }