我正在编写一个与BLUETOOTH硬件配对和通信的android程序。我可以打开和关闭蓝牙设备......但是我无法在范围内搜索蓝牙设备并存储或显示(我是android和java的新手)。 我无法理解developer.android.com中的代码。 所以我在这里张贴...请帮助..谢谢你。
这是我的代码..
public void onToggleClicked(View view) {
if (!((Switch) findViewById(R.id.switch1)).isChecked()) {
mBluetoothAdapter.disable();
} else {
Intent enableBtIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == REQUEST_ENABLE_BT) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
Toast.makeText(this.getBaseContext(),
"Bluetooth IS switched ON now...", Toast.LENGTH_SHORT)
.show();
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this.getBaseContext(),
"Bluetooth IS switched OFF now...", Toast.LENGTH_SHORT)
.show();
((Switch) findViewById(R.id.switch1)).setChecked(false);
}
}
}