简体   繁体   中英

Detecting socket type (Secure and Insecure) bluetooth android

Hot to detecting socket type bluetooth in android? for example;

I connect to a Bluetooth printer sometimes works with

device.createInsecureRfcommSocketToServiceRecord ( uuid ) ;

(Samsung , Motorola ) but for other devices such as Lenovo , Huawei , works with

device.createRfcommSocketToServiceRecord ( uuid ) ;

How to detect the type of socket if it is safe or unsafe.

problem is a core android, condition is :

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);  
}

very good for me, bye!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM