本文共 972 字,大约阅读时间需要 3 分钟。
移步:
/** * 调用系统对话框开启蓝牙 * * @param view */public void openBluetoothBySystem(View view) { Toast.makeText(this, "调用系统对话框开启蓝牙", Toast.LENGTH_SHORT).show(); Intent openBluetoothBySystemIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); // 第二个参数是请求码 startActivityForResult(openBluetoothBySystemIntent, 1);}
/** * 静默方式开启蓝牙 * * @param view */public void openBluetoothByCode(View view) { Toast.makeText(this, "静默方式开启蓝牙", Toast.LENGTH_SHORT).show(); BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothAdapter.enable();}
/** * 静默方式关闭蓝牙 * * @param view */public void closeBluetoothByCode(View view) { Toast.makeText(this, "静默方式关闭蓝牙", Toast.LENGTH_SHORT).show(); BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // 关闭蓝牙 bluetoothAdapter.disable();}