文章:Android 蓝牙设备的查找和连接
以下部分代码摘自网络。
public class MainActivity extends AppCompatActivity {
private TextView mTextView;
private BluetoothAdapter mBluetoothAdapter;
private Button button_id1;
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String action = intent.getAction();
// 获得已经搜索到的蓝牙设备
if (action.equals(BluetoothDevice.ACTION_FOUND)) {
BluetoothDevice device = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// 搜索到的不是已经绑定的蓝牙设备
if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
// 显示在TextView上
mTextView.append(device.getName() + ":"
+ device.getAddress()+