iT邦幫忙

2021 iThome 鐵人賽

DAY 20
0
自我挑戰組

三十天寫出上架Android App系列 第 20

官方介紹的Bluetooth

  • 分享至 

  • xImage
  •  

https://developer.android.com/guide/topics/connectivity/bluetooth

使用Bluetooth APIs 可以做到:
Scan for other Bluetooth devices. 掃瞄藍芽裝置
Query the local Bluetooth adapter for paired Bluetooth devices. 查詢並配對
Establish RFCOMM channels. 建立通訊
Connect to other devices through service discovery. 使用Service 採索進行連線
Transfer data to and from other devices. 傳輸檔案
Manage multiple connections. 管理多裝置

使用藍芽連線主要有個步驟(基本要求工作):
Setting up Bluetooth.
Finding devices that are either paired or available in the local area.
Connecting devices.
Transferring data between devices.

在android.bluetooth 提供的功能,有以下幾個主要的類別:

  • BluetoothAdapter
  • BluetoothDevice
  • BluetoothSocket
  • BluetoothServerSocket
  • BluetoothClass
  • BluetoothProfile
  • BluetoothHeadset
  • BluetoothA2dp
  • BluetoothHealth
  • BluetoothHealthCallback
  • BluetoothHealthAppConfiguration
  • BluetoothProfile.ServiceListener

連線時,主要兩個步驟:

  1. Get the BluetoothAdapter
  2. Enable Bluetooth
  3. Get a BluetoothServerSocket by calling listenUsingRfcommWithServiceRecord().
  4. Start listening for connection requests by calling accept().
  5. Unless you want to accept additional connections, call close().

上一篇
初淺認識Room
系列文
三十天寫出上架Android App20
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言