检测套接字类型(安全和不安全)蓝牙 android

Detecting socket type (Secure and Insecure) bluetooth android

在 android 中检测插座类型蓝牙很热?例如;

我连接到蓝牙打印机有时可以使用

device.createInsecureRfcommSocketToServiceRecord (uuid);

(三星、摩托罗拉)但对于联想、华为等其他设备,适用于

device.createRfcommSocketToServiceRecord (uuid);

如何检测套接字的类型是安全的还是不安全的。

问题是一个核心android,条件是:

UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");  
int sdk = Integer.parseInt(Build.VERSION.SDK);  
if(sdk < 17){  
    //sdk 4.2.2?? java.io.IOException: Connection refused   
    socket = device.createInsecureRfcommSocketToServiceRecord(uuid);  
}else {  
    socket = device.createRfcommSocketToServiceRecord(uuid);  
}

非常适合我,再见!