この記事は最終更新日から1年以上経過しています。
GPS機能についてはこちら1828
端末自身の[設定]-[位置情報とセキュリティ]より、「Wi-Fi/モバイルネットワークで位置を検出」がONに設定されているかを取得します。
OFFに設定されている場合にダイアログを表示して設定画面を呼び出す処理をしています。
2 | String GpsStatus = android.provider.Settings.Secure.getString(getContentResolver(), Secure.LOCATION_PROVIDERS_ALLOWED); |
4 | if (GpsStatus.indexOf( "network" , 0 ) < 0 ) { |
6 | AlertDialog.Builder ad = new AlertDialog.Builder( this ); |
7 | ad.setMessage( "Wi-Fi/モバイルネットワークで\n位置を検出する機能がOFFになっています。\n設定画面を開きますか?" ); |
8 | ad.setPositiveButton( "OK" , new DialogInterface.OnClickListener() { |
9 | public void onClick(DialogInterface dialog, int whichButton) { |
11 | Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); |
12 | startActivity(intent); |
15 | ad.setNegativeButton( "Cancel" , new DialogInterface.OnClickListener() { |
16 | public void onClick(DialogInterface dialog, int whichButton) { |
API Level3(Android 1.5)以降、セキュリティ上の問題で設定を強制的に変更することはできません。