- Android
- 2012-04-19
2,354 views
GPS機能についてはこちら1828
端末自身の[設定]-[位置情報とセキュリティ]より、「Wi-Fi/モバイルネットワークで位置を検出」がONに設定されているかを取得します。
OFFに設定されている場合にダイアログを表示して設定画面を呼び出す処理をしています。
// 位置情報設定の状態を取得 String GpsStatus = android.provider.Settings.Secure.getString(getContentResolver(), Secure.LOCATION_PROVIDERS_ALLOWED); if (GpsStatus.indexOf("network", 0) < 0) { //Wi-Fi/モバイルネットワークで位置を検出が無効だった場合 AlertDialog.Builder ad = new AlertDialog.Builder(this); ad.setMessage("Wi-Fi/モバイルネットワークで\n位置を検出する機能がOFFになっています。\n設定画面を開きますか?"); ad.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //設定画面を呼び出す Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); } }); ad.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int whichButton) { //何もしない } }); ad.create(); ad.show(); } else if { } else { //有効だった場合 }
API Level3(Android 1.5)以降、セキュリティ上の問題で設定を強制的に変更することはできません。
var button = document.createElement("input"); button.type = "button"; button.value = "button"; button.className = "button"; // onclickイベントを追加 button.setAttribute("onclick", "func();"); document.body.appendChild(button);
MyActivity.java
Intent intent = new Intent(this, NextActivity.class); intent.putExtra("EXNAME", "example"); intent.putExtra("EXINT", 30); startActivity(intent);
NextActivity.java
Intent intent = getIntent(); String exname = intent.getStringExtra("EXNAME"); int exint = intent.getIntExtra("EXINT", [デフォルト値]);
android/1683で紹介していた方法で
エラーが発生したので修正しました。
surfaceChanged内のsetPreviewSizeメソッドでエラー発生
元は以下のようなコード
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { Camera.Parameters parameters = mCamera.getParameters(); parameters.setPreviewSize(w, h); mCamera.setParameters(parameters); mCamera.startPreview(); }