Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2108680
  • 博文数量: 413
  • 博客积分: 10926
  • 博客等级: 上将
  • 技术积分: 3862
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-09 18:14
文章分类

全部博文(413)

文章存档

2015年(5)

2014年(1)

2013年(5)

2012年(6)

2011年(138)

2010年(85)

2009年(42)

2008年(46)

2007年(26)

2006年(59)

分类:

2011-05-11 15:34:38

  1. Docs
    • Bluetooth (Fundamentals & samples)
      http://developer.android.com/guide/topics/wireless/bluetooth.html
    • Samples
      BluetoothChat
    • xxx
  2. Four major tasks
    • Set up Bluetooth
    • Find devices that are either paired or available in the local area
    • Connect devices
    • Transfer data between devices.
  3. Important Classes
    • BluetoothAdapter
    • BluetoothDevice
    • BluetoothServerSocket
    • BluetoothSocket
      Notes:
      If the two devices have not been previously paired, then the Android framework will automatically show a pairing request notification or dialog to the user during the connection procedure.
    • xxx
  4. Flow Char
    • Prepare
      Check to see if Bluetooth is supported/disabled;
      Enable Bluetooth
    • As server
      BluetoothAdapter--------->BluetoothServerSocket----<accept>---->BluetoothSocket-------->Input/OutputStream
    • As client
      BluetoothAdapter--------->Devices Address String-------->BluetoothDevice---->BluetoothSocket-------->BluetoothSocket-------->Input/OutputStream

      or

      BluetoothAdapter--------->BluetoothDevice---->BluetoothSocket-------->BluetoothSocket[connected]-------->Input/OutputStream
    • xxx
  5. Monitor Bluetooth state
    (From: http://developer.android.com/guide/topics/wireless/bluetooth.html)
    Listen for the ACTION_STATE_CHANGED broadcast Intent, which the system will broadcast whenever the Bluetooth state has changed. This broadcast contains the extra fields EXTRA_STATE and EXTRA_PREVIOUS_STATE, containing the new and old Bluetooth states, respectively. Possible values for these extra fields are STATE_TURNING_ON, STATE_ON, STATE_TURNING_OFF, and STATE_OFF. Listening for this broadcast can be useful to detect changes made to the Bluetooth state while your app is running.
  6. About UUID
    When to invoke the following methods, an argument of UUID need to provided,

    - BluetoothAdapter: Create BluetoothServerSocket
    a) BluetoothServerSocket listenUsingInsecureRfcommWithServiceRecord(String name, UUID uuid)
    b) BluetoothServerSocket listenUsingRfcommWithServiceRecord(String name, UUID uuid)

    - BluetoothDevice: Create BluetoothSocket
    a) BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid)
    b) BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid)

    If you specify your own UUID when to create BluetoothServerSocket on server side by invoking listenUsingInsecureRfcommWithServiceRecord/listenUsingRfcommWithServiceRecord, you must specify the same UUID when to connect to the server by invoking createInsecureRfcommSocketToServiceRecord/createRfcommSocketToServiceRecord.

    But, if you are connecting to a Bluetooth serial board then try using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB.

    (More details:
    - http://developer.android.com/guide/topics/wireless/bluetooth.html, see "Connecting Devices" section;
    - http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html, see description of mehtods listenUsingInsecureRfcommWithServiceRecord/listenUsingRfcommWithServiceRecord;
    - http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html, see description of methods createInsecureRfcommSocketToServiceRecord/createRfcommSocketToServiceRecord.)
  7. xxx
阅读(2911) | 评论(0) | 转发(0) |
0

上一篇:[Android] App Widget

下一篇:[Android] Accounts

给主人留下些什么吧!~~