C/C++プログラマの管理者が, Androidプログラムにチャレンジ. AndroidプログラミングのTipsをメモっていく予定です.

Bluetoothの設定画面を呼び出すには, インテント(Intent)を利用する.


     ↓


設定画面の呼び出し

  • Bluetooth02.java
    • ACTION_BLUETOOTH_SETTINGSを指定して, Intentのインスタンスを生成する.
    • startActivityメソッドで, インテント呼出しする.
package com.moonlight_aska.android.bluetooth02;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Bluetooth02 extends Activity implements View.OnClickListener {
  private Button mSettingBtn;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mSettingBtn = (Button)findViewById(R.id.setting_btn);
    mSettingBtn.setOnClickListener(this);
  }

  @Override
  public void onClick(View v) {
    // TODO Auto-generated method stub
    if (v == mSettingBtn) {
      Intent intent = new Intent(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
      startActivity(intent);
    }
  }
}



コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Menu


逆引き(基礎編)

画面表示/操作(49)

フラグメント(1)

逆引き(応用編)

Firebase(2)

AD



管理人/副管理人のみ編集できます