2013-03-12 47 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