標籤:android style io ar color os sp for on
一、BluetoothAdapter--藍芽適配器(本機)
BluetoothAdapter裡的方法很多,常用的有以下幾個:
(1)cancelDiscovery() 根據字面意思,是取消發現,也就是說當我們正在搜尋裝置的時候調用這個方法將不再繼續搜尋
(2)disable()關閉藍芽
(3)enable()開啟藍芽,這個方法開啟藍芽不會彈出提示,
更多的時候我們需要問下使用者是否開啟,以下這兩行代碼同樣是開啟藍芽,不過會提示使用者:
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);//也可以寫成startActivity(enableIntent);
(4)getAddress()擷取本地藍芽地址
(5)getDefaultAdapter()擷取預設BluetoothAdapter,實際上,也只有這一種方法擷取BluetoothAdapter
(6)getName()擷取本地藍芽名稱
(7)getRemoteDevice(String address)根據藍芽地址擷取遠程藍牙裝置
(8)getState()擷取本地藍芽適配器目前狀態(感覺可能調試的時候更需要)
(9)isDiscovering()判斷當前是否正在尋找裝置,是返回true
(10)isEnabled()判斷藍芽是否開啟,已開啟返回true,否則,返回false
(11)listenUsingRfcommWithServiceRecord(String name,UUID uuid)根據名稱,UUID建立並返回BluetoothServerSocket,這是建立BluetoothSocket伺服器端的第一步
(12)startDiscovery()開始搜尋,這是搜尋的第一步
二、BluetoothDevice--藍牙裝置(遠程)
createRfcommSocketToServiceRecord(UUIDuuid)根據UUID建立並返回一個BluetoothSocket
這個方法也是我們擷取BluetoothDevice的目的——建立BluetoothSocket
這個類其他的方法,如getAddress(),getName(),同BluetoothAdapter
三、BluetoothSocket--藍芽socket介面
四、BluetoothServerSocket--表示一個開放的伺服器socket,監聽進入的串連請求
五、bluetooth包下還有4個類,BluetoothClass 、BluetoothClass.Device、BluetoothClass.Device.Major、BluetoothClass.Service
Android藍芽開發(二):相關的API簡介