1. After launching the app:
Determine if Bluetooth is turned on (all functions must be used in case of tooth opening)
Turned on: Bluetooth Communication Service in startup code
Not open: Publish turns on Bluetooth intent (System) and returns to the entry operation based on activity
Turn on success, start the Bluetooth communication Service in code
User points back or fails to exit the app
2. Bluetooth Device list:
2.1 Show already paired list:
Registering a Bluetooth Device Discovery broadcast
Add the discovered devices to the list in the broadcast
2.2 When the user points to scan, the Bluetooth discovery is initiated and a broadcast event is received when the device is discovered.
2.3 When a user points an entry, the Mac that changes the entry is returned to the main activity (Startactivityforresult activity is called)
3. Enable the device to discover
Private void ensurediscoverable () { "ensure discoverable"); if (Mbluetoothadapter.getscanmode ()! = bluetoothadapter.scan_mode_connectable_discoverable) { New Intent (bluetoothadapter.action_request_discoverable); - ); StartActivity (discoverableintent); } }
View Code
Android Bluetooth Communication Programming memo