ボタンでアプリケーションをクリックすると、プログラムでBluetoothを有効にしたいのですが、以下のコードを使用していますが、Bluetoothを有効にできますBluetoothを有効にするダイアログ私はアプリケーションを終了している、私はアプリケーションを終了したくない私は同じ画面を表示したいBluetoothを有効にした後にも私はこれを行うことができます下のコードを確認してください私はBluetoothとonActivityResultコード方法。 enter code here
アプリケーションボタンをクリックしてプログラムでBluetoothをオンにすると終了する
if(v.getId() == R.id.Button)
{
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
final ArrayAdapter mArrayAdapter = null;
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
}
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch(requestCode) {
case REQUEST_ENABLE_BT:
if (resultCode == RESULT_OK) {
String name = data.getStringExtra("Bluetooth Enabled");
Toast.makeText(this, "You have chosen the book: " + " " + name, Toast.LENGTH_LONG).show();
break;
}
}
}
私は返信をすることができます... –