Download  >  Manual Download  >  ANDROID Bluetooth programming WORD document doc format

ANDROID Bluetooth programming WORD document doc format
Classify:Mobile terminalViews:1153Download:29
Using the BluetoothAdapter class, you can find surrounding Bluetooth devices on your Android device and then pair (bind) them. Bluetooth communication is transmitted to each other based on the unique address MAC. Considering security issues, Bluetooth communication needs to be paired first. Then start to connect to each other. After the connection, the devices will share the same RFCOMM channel to transmit data to each other. Currently, these implementations are implemented on Android 2.0 or higher SDK.
1. Finding/discovering devices
For Android to find Bluetooth devices, use the startDiscovery() method of the BluetoothAdapter class to perform an asynchronous method to obtain surrounding Bluetooth devices. Because it is an asynchronous method, we There is no need to consider the thread being blocked. The whole process takes about 12 seconds. At this time, we then register a BroadcastReceiver object to receive the found Bluetooth device information. We filter the ACTION_FOUND Intent action to obtain the detailed information of each remote device. Each BluetoothDevice object and the device type BluetoothClass of the object are included in the Intent fields EXTRA_DEVICE and EXTRA_CLASS through additional parameters, sample code
private final BroadcastReceiver cwjReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE) ;
            myArrayAdapter.add(device.getName() + " android123 " + device.getAddress()); // Get the device name and mac address
                                                                                                                                     
// Register this BroadcastReceiver
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(cwjReceiver, filter);
Finally, android123 reminds everyone that you need to pay attention to, remember Override the onDestory() method in Service or Activity, and use the unregisterReceiver method to unregister the BroadcastReceiver object to ensure that resources are correctly recycled.
Some other status changes are ACTION_SCAN_MODE_CHANGED extra parameters EXTRA_SCAN_MODE and EXTRA_PREVIOUS_SCAN_MODE and SCAN_MODE_CONNECTABLE_DISCOVERABLE, SCAN_MODE_CONNECTABLE and SCAN_MODE_NONE, Bluetooth module

All resources on this website are contributed and published by netizens, or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this website are for learning and reference only. Please do not use them for commercial purposes, otherwise you will be responsible for all consequences incurred! If there is any infringement, please contact us to delete and remove it. Contact information: admin@php.cn

Latest courses

See more
  • [Web front-end] Node.js quick start
    [Web front-end] Node.js quick start
    This course is specially designed for beginners and aims to help students quickly master the basic knowledge and core technologies of Node.js. The course starts with the installation and environment configuration of Node.js, and gradually analyzes its asynchronous programming model, module system and event-driven mechanism in depth. Through a wealth of practical cases, students will learn how to use Node.js to build an efficient and stable web server, process HTTP requests and responses, and perform file operations and database interactions. In addition, the course will also introduce typical application scenarios of Node.js in front-end development, helping students quickly improve their practical capabilities and easily cope with the challenges of front-end development.
  • Complete collection of foreign web development full-stack courses
    Complete collection of foreign web development full-stack courses
    This course is a comprehensive tutorial covering HTML, CSS, JavaScript, Vue.js, React, Flutter and mobile APP development. From basic web page production to complex front-end and back-end interactions, to practical development of mobile applications, the courses are rich in content and highly practical. Through a series of practical projects, students will gain an in-depth understanding of and master various development skills and quickly grow into full-stack development engineers. Both beginners and experienced developers can benefit from it. Through the study of this course, you will have the ability to independently develop web applications and mobile applications, laying a solid foundation for future career development.
  • Go language practical GraphQL
    Go language practical GraphQL
    This course is designed to help learners master how to use Go language to implement GraphQL services. The course starts with the basic knowledge of GraphQL, and deeply analyzes the characteristics and advantages of its data query language. Then, combined with the characteristics of the Go language, it explains in detail how to build a GraphQL server, process requests, define data patterns, etc. Through rich practical cases, learners will learn how to integrate GraphQL in actual projects to improve the flexibility and efficiency of data interaction. The course is suitable for developers with a certain foundation in Go language and is a must-have for building efficient and modern APIs.
  • 550W fan master learns JavaScript from scratch step by step
    550W fan master learns JavaScript from scratch step by step
    This course is specially designed for beginners and is taught by Google bosses. The course starts from the basic knowledge of JavaScript and gradually deepens, covering syntax, functions, objects, event processing, etc. Through vivid cases and practical exercises, students can quickly master the core skills of JavaScript. The boss will personally answer students' questions and share programming experience, allowing students to grow into JavaScript masters in a relaxed and pleasant atmosphere. Whether you are a novice at programming or a developer looking to improve your skills, this course will be your best choice for learning JavaScript.
  • Python master Mosh, a beginner with zero basic knowledge can get started in 6 hours
    Python master Mosh, a beginner with zero basic knowledge can get started in 6 hours
    This course takes you on a programming journey. Starting from scratch, this 6-hour course will guide you through the fundamentals and advanced concepts of Python. Whether you're a beginner or an experienced programmer looking to improve your skills, Mosh's in-depth explanations and clear teaching methods will get you up to speed with Python quickly. Learn more about variables, data types, conditionals, loops, functions, objects, and modules and solidify your understanding with hands-on exercises. This course is ideal for learning Python and preparing you for a variety of career fields. Mosh's expertise and passion for education will give you the confidence to start on your path to becoming a proficient Python developer.