㈠ 濡备綍浣跨敤Android钃濈堕寮鍙
銆銆Android骞冲彴鏀鎸佽掴鐗欑绣缁滃岗璁镙堬纴瀹炵幇钃濈堕璁惧囦箣闂存暟鎹镄勬棤绾夸紶杈撱傛湰鏂囨。鎻忚堪浜嗘庢牱鍒╃敤android骞冲彴鎻愪緵镄勮掴鐗橝PI铡诲疄鐜拌掴铡嬭惧囦箣闂寸殑阃氢俊銆傝掴鐗椤叿链塸oint-to-point 鍜 multipoint涓ょ嶈繛鎺ュ姛鑳姐
銆銆浣跨敤钃濈堕API锛屽彲浠ュ仛鍒帮细
銆銆* 鎼灭储钃濈堕璁惧
銆銆* 浠庢湰鍦扮殑Bluetooth adapter涓镆ヨ㈠凡缁忛厤瀵圭殑璁惧
銆銆* 寤虹珛RFCOMM阃氶亾
銆銆* 阃氲繃service discovery杩炴帴鍒板叾瀹冭惧
銆銆* 鍦ㄨ惧囦箣闂翠紶杈撴暟鎹
銆銆* 绠$悊澶氢釜杩炴帴
銆銆锘虹鐭ヨ瘑
銆銆链鏂囨。浠嬬粛浜嗗备綍浣跨敤Android镄勮掴鐗橝PI𨱒ュ畬鎴愮殑锲涗釜蹇呰佺殑涓昏佷换锷★纴浣跨敤钃濈堕杩涜岃惧囬氢俊锛屼富瑕佸寘钖锲涗釜閮ㄥ垎锛氲掴鐗栾剧疆銆佹悳绱㈣惧囷纸閰嶅圭殑鎴栧彲瑙佺殑锛夈佽繛鎺ャ佷紶杈撴暟鎹銆
銆銆镓链夌殑钃濈堕API鍦╝ndroid.bluetooth鍖呬腑銆傚疄鐜拌繖浜涘姛鑳戒富瑕侀渶瑕佷笅闱㈣繖鍑犱釜绫诲拰鎺ュ彛锛
銆銆BluetoothAdapter
銆銆浠h〃链鍦拌掴鐗欓傞厤鍣锛堣掴鐗椤彂灏勫櫒锛夛纴鏄镓链夎掴鐗欎氦浜掔殑鍏ュ彛銆傞氲繃瀹冨彲浠ユ悳绱㈠叾瀹冭掴鐗栾惧囷纴镆ヨ㈠凡缁忛厤瀵圭殑璁惧囧垪琛锛岄氲繃宸茬煡镄凪AC鍦板潃鍒涘缓BluetoothDevice锛屽垱寤筑luetoothServerSocket鐩戝惉𨱒ヨ嚜鍏跺畠璁惧囩殑阃氢俊銆
銆銆BluetoothDevice
銆銆浠h〃浜嗕竴涓杩灭镄勮掴鐗栾惧囷纴 浣跨敤瀹冭锋眰杩灭钃濈堕璁惧囱繛鎺ユ垨钥呰幏鍙 杩灭钃濈堕璁惧囩殑钖岖О銆佸湴鍧銆佺岖被鍜岀粦瀹氱姸镐併 锛埚叾淇℃伅鏄灏佽呭湪 bluetoothsocket 涓锛 銆
銆銆BluetoothSocket
銆銆浠h〃浜嗕竴涓钃濈堕濂楁帴瀛楃殑鎺ュ彛锛堢被浼间簬 tcp 涓镄勫楁帴瀛楋级 锛屼粬鏄搴旂敤绋 搴忛氲繃杈揿叆銆佽緭鍑烘祦涓庡叾浠栬掴鐗栾惧囬氢俊镄勮繛鎺ョ偣銆
銆銆BluetoothServerSocket
銆銆浠h〃镓揿紑链嶅姟杩炴帴𨱒ョ洃钖鍙鑳藉埌𨱒ョ殑杩炴帴璇锋眰 锛埚睘浜 server 绔锛 锛 涓轰简杩炴帴涓や釜钃濈堕璁惧囧繀椤绘湁涓涓璁惧囦綔涓烘湇锷″櫒镓揿紑涓涓链嶅姟濂楁帴瀛椼 褰撹繙绔璁惧囧彂璧疯繛 鎺ヨ繛鎺ヨ锋眰镄勬椂鍊欙纴骞朵笖宸茬粡杩炴帴鍒颁简镄勬椂鍊欙纴Blueboothserversocket 绫诲皢浼氲繑锲炰竴涓 bluetoothsocket銆
銆銆BluetoothClass
銆銆鎻忚堪浜嗕竴涓璁惧囩殑鐗规э纸profile锛夋垨璇ヨ惧囦笂镄勮掴鐗椤ぇ镊村彲浠ユ彁渚涘摢浜涙湇锷(service)锛屼絾涓嶅彲淇°傛瘆濡傦纴璁惧囨槸涓涓鐢佃瘽銆佽$畻链烘垨镓嬫寔璁惧囷绂璁惧囧彲浠ユ彁渚沘udio/telephony链嶅姟绛夈傚彲浠ョ敤瀹冩潵杩涜屼竴浜沀I涓婄殑鎻愮ず銆
銆銆BluetoothProfile
銆銆BluetoothHeadset
銆銆鎻愪緵镓嬫満浣跨敤钃濈堕钥虫満镄勬敮鎸併傝繖镞㈠寘𨰾钃濈堕钥虫満鍜屽厤鎻愶纸V1.5锛夋ā寮忋
銆銆BluetoothA2dp
銆銆瀹氢箟楂桦搧璐ㄧ殑阔抽戯纴鍙浠ヤ粠涓涓璁惧囦紶杈揿埌鍙︿竴涓钃濈堕杩炴帴銆 钬淎2DP镄勨濅唬琛ㄩ珮绾ч煶棰戝垎閰嶆ā寮忋
銆銆BluetoothHealth
銆銆浠h〃浜嗗尰鐤楄惧囬厤缃浠g悊鎺у埗镄勮掴鐗欐湇锷
銆銆BluetoothHealthCallback
銆銆涓涓鎶借薄绫伙纴浣跨敤瀹炵幇BluetoothHealth锲炶皟銆备綘蹇呴’镓╁𪾢杩欎釜绫诲苟瀹炵幇锲炶皟鏂规硶鎺ユ敹镟存柊搴旂敤绋嫔簭镄勬敞鍐岀姸镐佸拰钃濈堕阃氶亾鐘舵佺殑鍙桦寲銆
銆銆
銆銆浠h〃涓涓搴旂敤绋嫔簭镄勯厤缃锛岃掴鐗椤尰鐤楃涓夋柟搴旂敤娉ㄥ唽涓庤繙绋嬭掴鐗椤尰鐤楄惧囦氦娴併
銆銆BluetoothProfile.ServiceListener
銆銆褰扑粬浠宸茬粡杩炴帴鍒版垨浠庢湇锷℃柇寮镞堕氱煡BluetoothProfile IPX镄勫㈡埛镞朵竴涓鎺ュ彛锛埚嵆杩愯屼竴涓鐗瑰畾镄勯厤缃鏂囦欢锛屽唴閮ㄦ湇锷★级銆
銆銆钃濈堕𨱒冮檺
銆銆涓轰简鍦ㄤ綘镄勫簲鐢ㄤ腑浣跨敤钃濈堕锷熻兘锛岃呖灏戣佸湪AndroidManifest.xml涓澹版槑涓や釜𨱒冮檺锛欱LUETOOTH锛堜换浣曡掴鐗欑浉鍏矨PI閮借佷娇鐢ㄨ繖涓𨱒冮檺锛 鍜 BLUETOOTH_ADMIN锛堣惧囨悳绱銆佽掴鐗栾剧疆绛夛级銆
銆銆涓轰简镓ц岃掴鐗欓氢俊锛屼緥濡傝繛鎺ヨ锋眰锛屾帴鏀惰繛鎺ュ拰浼犻佹暟鎹閮藉繀椤绘湁BLUETOOTH𨱒冮檺銆
銆銆蹇呴’瑕佹眰BLUETOOTH_ADMIN镄勬潈闄愭潵钖锷ㄨ惧囧彂鐜版垨镎岖旱钃濈堕璁剧疆銆傚ぇ澶氭暟搴旂敤绋嫔簭閮介渶瑕佽繖涓𨱒冮檺鑳藉姏锛屽彂鐜板綋鍦扮殑钃濈堕璁惧囥傛ゆ潈闄愭巿浜埚叾浠栫殑鑳藉姏涓嶅簲璇ヤ娇鐢锛岄櫎闱炲簲鐢ㄧ▼搴忔槸涓涓钬灭数婧愮$悊钬濓纴灏嗘牴鎹鐢ㄦ埛瑕佹眰淇鏀圭殑钃濈堕璁剧疆
銆銆娉ㄩ喷锛氲佽锋眰BLUETOOTH_ADMIN镄勮瘽锛屽繀椤昏佸厛链塀LUETOOTH銆
銆銆鍦ㄤ綘镄勫簲鐢╩anifest 鏂囦欢涓澹版槑钃濈堕𨱒冮檺銆备緥濡傦细
銆銆<manifest ... >
銆銆<uses-permission android:name="android.permission.BLUETOOTH" />
銆銆...
銆銆</manifest>
銆銆阃氲繃镆ョ湅<uses-permission>璧勬枡𨱒ュ0鏄庡簲鐢ㄦ潈闄愯幏鍙栨洿澶氱殑淇℃伅銆
銆銆钃濈堕璁剧疆
銆銆鍦ㄤ綘镄勫簲鐢ㄩ氲繃钃濈堕杩涜岄氢俊涔嫔墠锛屼綘闇瑕佺‘璁よ惧囨槸钖︽敮鎸佽掴鐗欙纴濡傛灉鏀鎸侊纴纭淇″畠琚镓揿紑銆
銆銆濡傛灉涓嶆敮鎸侊纴鍒欎笉鑳戒娇鐢ㄨ掴鐗椤姛鑳姐傚傛灉鏀鎸佽掴鐗欙纴浣嗕笉鑳藉熶娇鐢锛屼綘鍒氲佸湪浣犵殑搴旂敤涓璇锋眰浣跨敤钃濈堕銆傝繖涓瑕佷袱姝ュ畬鎴愶纴浣跨敤BluetoothAdapter銆