Implementation process of Android 6.0 Bluetooth communication for Android adaptation

Note in advance: Android Bluetooth needs to locate the permission application. It can only be used after the user manually confirms the permission in Android 6.0. You can query the data yourself. If it's troublesome, you can use the tool class integrated by the third-party bmob. See the details http://blog.csdn.net/qq_30379689/article/details/52223244 @H_ 301_ 4@

Bluetooth connection process: 1. Query whether the user turns on Bluetooth. 2. Search for available Bluetooth nearby. 3. Bluetooth pairing. 4. Make a Bluetooth connection. 5. Gets the input and output streams. 6. Send a message@ H_ 301_ 4@

Sun my beautiful picture: @ h_ 301_ 4@

@H_ 301_ 4@ @H_ 301_ 4@

Experimental effect drawing: @ h_ 301_ 4@

@H_ 301_ 4@@H_ 301_ 4@

Permissions required for implementation: due to Android 4 Versions above x use Bluetooth. You need to turn on the location permission to search the nearby Bluetooth device @ H_ 301_ 4@

Server @ h_ 301_ 4@

Implementation ideas: 1. Get the local Bluetooth device. 2. The communication between Bluetooth requires a unique UUID to match the correct device. Use the UUID to obtain the Bluetooth communication socket. 3. Open the thread @ h to get data_ 301_ 4@

Client @ h_ 301_ 4@

Implementation ideas: 1. Check whether Bluetooth is turned on. 2. Sign up for a series of Bluetooth broadcasts. 3. Because Bluetooth sends a broadcast every stage, the corresponding method is realized according to the broadcast. 4. Bluetooth pairing - > Bluetooth connection - > send message (UUID must be the same) @ h_ 301_ 4@

Bluetooth broadcast content: @ h_ 301_ 4@

ACTION_ STATE_ Changed sends an action when Bluetooth is turned on or off_ Found sends an action when you match a nearby Bluetooth device_ DISCOVERY_ Started send action when you start searching for nearby Bluetooth devices_ DISCOVERY_ Finished sends an action when you finish searching for nearby Bluetooth devices_ BOND_ STATE_ Changed send @ h when your Bluetooth device matching status changes_ 301_ 4@

Source code download: http://xiazai.jb51.net/201609/yuanma/Androidrobot (jb51.net). rar@H_301_4 @

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips@ H_ 301_ 4@

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>