Android 检查蓝牙是否启用
示例
private static final int REQUEST_ENABLE_BT = 1; // 唯一请求码BluetoothAdapter mBluetoothAdapter;
// ...
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
// ...
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_ENABLE_BT) {
if (resultCode == RESULT_OK) {
// 蓝牙已启用
} else if (resultCode == RESULT_CANCELED) {
// 蓝牙未启用
}
}
}
以上是 Android 检查蓝牙是否启用 的全部内容, 来源链接: utcz.com/z/343142.html