蓝牙连接

private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); 
 
private void connect(BluetoothDevice device) { 
     m_Device
= device; 
     
BluetoothSocket tmp = null; 
 
     
// Get a BluetoothSocket for a connection with the 
     
// given BluetoothDevice 
     
try { 
         tmp
= device.createRfcommSocketToServiceRecord(MY_UUID); 
     
} catch (IOException e) { 
 
     
} 
     m_Socket
= tmp; 
 
     m_BluetoothAdapter
.cancelDiscovery(); 
 
     
try { 
         
// This is a blocking call and will only return on a 
         
// successful connection or an exception 
         m_Socket
.connect(); 
     
} catch (IOException e) { 
     
try { 
       m_Socket
.close(); 
     
}catch (IOException e2) { 
 
         
} 
     
return; 
 
     
} 
用上述方法连接老是出现错误,不知道他人这样用过没 后来

tmp = device.createRfcommSocketToServiceRecord(MY_UUID); 
改为

Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class}); 
         tmp
= (BluetoothSocket) m.invoke(device, 1); 
可以了 无语中

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值