文字の入力欄をダイアログで表示します。
1 | EditText editView = new EditText( this ); |
2 |
3 | new AlertDialog.Builder( this ) |
4 | .setIcon(R.drawable.ic_dialog_info) |
5 | .setTitle( "ダイアログのタイトル" ) |
6 | .setView(editView) |
7 | .setPositiveButton( "OK" , new DialogInterface.OnClickListener() { |
8 | public void onClick(DialogInterface dialog, int whichButton) { |
9 | // OKボタンの処理 |
10 | } |
11 | }) |
12 | .setNegativeButton( "キャンセル" , new DialogInterface.OnClickListener() { |
13 | public void onClick(DialogInterface dialog, int whichButton) { |
14 | } |
15 | }) |
16 | .show(); |
GPS機能についてはこちら1828
端末自身の[設定]-[位置情報とセキュリティ]より、「Wi-Fi/モバイルネットワークで位置を検出」がONに設定されているかを取得します。
OFFに設定されている場合にダイアログを表示して設定画面を呼び出す処理をしています。
1 | // 位置情報設定の状態を取得 |
2 | String GpsStatus = android.provider.Settings.Secure.getString(getContentResolver(), Secure.LOCATION_PROVIDERS_ALLOWED); |
3 |
4 | if (GpsStatus.indexOf( "network" , 0 ) < 0 ) { |
5 | //Wi-Fi/モバイルネットワークで位置を検出が無効だった場合 |
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) { |
10 | //設定画面を呼び出す |
11 | Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); |
12 | startActivity(intent); |
13 | } |
14 | }); |
15 | ad.setNegativeButton( "Cancel" , new DialogInterface.OnClickListener() { |
16 | public void onClick(DialogInterface dialog, int whichButton) { |
17 | //何もしない |
18 | } |
19 | }); |
20 | ad.create(); |
21 | ad.show(); |
22 | } else if { |
23 | } else { |
24 | //有効だった場合 |
25 | } |
API Level3(Android 1.5)以降、セキュリティ上の問題で設定を強制的に変更することはできません。