2013-03-12 148 views
4

所以我正在研究一个连接到嵌入式蓝牙设备的应用程序。该设备在不同版本和我的测试设备上推出,每个作品都很好。通过安全的rfcomm套接字进行通信。然而,另一套设备给我的小兵。它们会失去边界状态。虽然它们被标记为配对,但每次建立连接时,都会要求我重新输入PIN码。这实在是不理想。此外,这种行为并不是所有的,但大多数设备。实际上,唯一不会忘记PIN的设备是Galaxy Nexus S.三星Galaxy Nexus,ACE,GIO和X10 mini Pro倾向于“忘记”以前配对的设备。使用API​​ lvl 10,我已经尝试过不安全的RFCOMM连接,但没有成功。 我迷失在这里。有没有人有想法?蓝牙忘记密码

此致敬礼!

+0

你检查了Android样品蓝牙聊天应用?它通过蓝牙提供完全功能的聊天,我试过了,它没有问题。试一试。 – k0sh 2013-03-12 13:52:19

+0

我希望我能投票下来...呵呵,只是开玩笑。但是,当然,我做到了。我花了数小时参考实施。我花了更多的时间用AIDL黑客来反映隐藏的蓝牙类,以建立一个程序化连接。我花了很多时间检查谷歌链接和实施dozends。我花了几个小时阅读了维基上的蓝牙规范以及几乎所有我可以在此找到的内容...... – 2013-03-12 14:09:15

+0

@JohnSmith不幸的是,没有办法降低评论...回到你的问题当你尝试使用哪种方法时检索套接字? – Rigotti 2013-03-12 18:16:04

回答

1

什么是您的设备的getBTMajorDeviceClass? 如果BluetoothClass.Device.Major.UNCATEGORIZED,尝试生成自己的UUID:

private UUID generateUuid() { 
String android_id = Secure.getString(getApplicationContext() 
    .getContentResolver(), Secure.ANDROID_ID); 
Log.i("System out", "android_id : " + android_id); 

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

final String tmDevice, tmSerial, androidId; 
tmDevice = "" + tm.getDeviceId(); 
Log.i("System out", "tmDevice : " + tmDevice); 
tmSerial = "" + tm.getSimSerialNumber(); 
Log.i("System out", "tmSerial : " + tmSerial); 
androidId = "" 
    + android.provider.Settings.Secure.getString(
     getContentResolver(), 
     android.provider.Settings.Secure.ANDROID_ID); 

UUID deviceUuid = new UUID(androidId.hashCode(), 
    ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()); 

return deviceUuid; 
} 

,并用它在套接字创建createRfcommSocketToServiceRecord(generateUuid());

*需要READ_PHONE_STATE