Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android蓝牙连接到配对设备_Java_Android_Bluetooth - Fatal编程技术网

Java Android蓝牙连接到配对设备

Java Android蓝牙连接到配对设备,java,android,bluetooth,Java,Android,Bluetooth,目前我有一个设备(Arduino的蓝牙模块),我想通过蓝牙连接。但每次我尝试联系时,什么都没发生。有人能告诉我我做错了什么吗? 我的代码: private static final UUID CONNUUID = UUID.fromString("0000110E-0000-1000-8000-00805F9B34FB"); public void connectDevice(BluetoothDevice bd){ try{ pairDia = Prog

目前我有一个设备(Arduino的蓝牙模块),我想通过蓝牙连接。但每次我尝试联系时,什么都没发生。有人能告诉我我做错了什么吗? 我的代码:

private static final UUID CONNUUID = UUID.fromString("0000110E-0000-1000-8000-00805F9B34FB");


public void connectDevice(BluetoothDevice bd){
       try{
           pairDia = ProgressDialog.show(this, "", "Connecting...", true, true);
           BluetoothSocket bs = bd.createInsecureRfcommSocketToServiceRecord(CONNUUID);

       }catch(Exception e){
           e.printStackTrace();
           this.finish();
       }
    }
}

最终,我想连接到设备,然后创建一个套接字,我可以读取和写入字节。如果您的设备已配对,谢谢。然后首先使用以下命令获取设备
UUID

final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);

// now tm.getdeviceID()...and is this equal to your CONNUUID?
设置蓝牙权限。。。在舱单上。。现在可以通过以下方式查看设备列表:

BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();   

Set<BluetoothDevice> devices = adapter.getBondedDevices();    

for (BluetoothDevice device : devices) {

   String sDeviceName = device.getName().trim();

   Log.d("device_found", sDeviceName);
}
BluetoothAdapter=BluetoothAdapter.getDefaultAdapter();
Set devices=adapter.getBondedDevices();
用于(蓝牙设备:设备){
字符串sDeviceName=device.getName().trim();
Log.d(“发现设备”,sDeviceName);
}

您忘记在
蓝牙插座上调用
connect()

// ...
BluetoothSocket bs = bd.createInsecureRfcommSocketToServiceRecord(CONNUUID);
bs.connect(); // note: blocking call
// ...

请参阅。

日志在
Logcat
中显示了什么以及
stackTrace
中的任何错误?没有堆栈跟踪,什么都没有