With nearly two years of wearable products gradually into people's lives, Bluetooth development has become an important module of Android development, let's say a Bluetooth API.1. There are two main APIs for Bluetooth development:Buletoothadapter: The local Bluetooth adapter
a client
To initialize a connection to a remote device, you must first obtain the local Bluetoothdevice object, and the related methods are mentioned in two articles of the Bluetoothadapter class of our Android Bluetooth API, and the relevant sample code is as follows:
Private class Connectthread extends Thread {Private final Bluetoothsocket Cwjsocket;Private final Bluetoothdevice Cwjdevice;Public Connectt
Preface
This chapter is about android. bluetooth. javasthclass, which is a part of Android bluetooth. It is used to describe the type, characteristics, and other information of a remote device. The getthclass () method is used to obtain the thclass object that represents the property of the remote device. Android 2.3 r1, translated from Sun Yat-sen University's "Android Club SYSU", welcome to visit their WI
:12.043:method Name (452): Setpasskey11-29 09:19:12.043:method Name (452): Setpin11-29 09:19:12.043:method Name (452): Settrust11-29 09:19:12.043:method Name (452): toString11-29 09:19:12.043:method Name (452): Writetoparcel11-29 09:19:12.043:method Name (452): convertpintobytes11-29 09:19:12.043:method Name (452): GetClass11-29 09:19:12.043:method Name (452): Notify11-29 09:19:12.043:method Name (452): Notifyall11-29 09:19:12.043:method Name (452): Wait11-29 09:19:12.051:method Name (452): Wait
A project needs to study the connection between non-ios devices and ios devices. I learned that Apple's official api does not support this operation, so I began to study Apple's private api.Many posts have been discussed on cc, but there is no substantial progress.After some google operations, I successfully enabled the iphone Bluetooth using a private api. Now I
Recently in the porting QQ IoT protocol, you need to read the device MAC address.Read the CC2541 device MAC address method, there is a direct read Mac register, you can also call the protocol stack API. This takes the form of a call API.1 /*use the protocol stack API to read MAC addresses*/2 StaticUint8 macaddr[b_addr_len]={0};//MAC address3uint8_t macstr[
1. Enable the bluetooth device explicitly
Intent intent=new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);startActivityForResult(intent,1);2. enable/disable the bluetooth device implicitly
Descrithadapter mAdapter = descrithadapter. getdefaadapter adapter (); // enable the bluetooth device mAdapter. enable (); // disable the
You can also directly use the existing API functions bthsetmode () and bthgetmode () for Bluetooth settings ().The two functions are defined in: bthutil. h, and then the dependent lib Library: bthutil. Lib needs to be added.Int bthsetmode (DWORDDwmode);
Int bthgetmode (DWORD *Pdwmode);
Return ValueReturns error_success on success or returns an error code on failure.
Among them, there are three dwmode val
MS, instead, Winsock is used for communication. When using Winsock for Bluetooth communication, you must specify a service. Therefore, you can specify a serial port for communication. Bluetooth Virtual Serial Port and Winsock both use the RFCOMM protocol, so the two are the same. Bluetooth communication using Winsock is simpler than
(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);}
2. Find a device
Using the thadapter class, you can search for remote devices (less than 10 meters) or other devices that have been matched (or bound) on your mobile phone. Of course, the demand determines that the bluetooth device of the other party is now open, or the "Discovery and enable" function may be available now (the other party's device
Bluetooth 1.2 vs 1.1:
1. Adaptive Frequency Hopping (AFH ):Adaptive Frequency Hopping TechnologyThe main function is to reduce interference problems between Bluetooth products and other wireless communication devices.
2. Extended synchronous connection-oriented links (ESCO ):Extended synchronous link-oriented channel technologyIt is used to provide audio transmission with high QoS, and can further meet the
In my last two articles blog post explained about Android Bluetooth awareness as well as APIs related to the introduction of Bluetooth ble search, connection and read.Do not know the children's shoes, please refer to:
Learn more about the basics of Android Bluetooth bluetooth--
Learn more about the Android
Android Bluetooth Low Energy (Android Low-power Bluetooth)
Android 4.3 (API Level 18) has introduced core functions of Bluetooth Low Energy (BLE, Low-power Bluetooth) and provided relevant APIs through which applications can scan devices and query services, characteristics (
Android4.3 (API level 18) introduces a built-in platform to support the central role of BLE, while providing APIs and app applications for discovering devices, querying services, and reading/writing characteristics. Unlike traditional Bluetooth (Classicbluetooth), Bluetooth low power (BLE) is designed to provide more significant low power consumption. This allows
, and then do the appropriate processing.Let's see how to turn on the Bluetooth device.1. In addition to the need to consider the API level at least 5, we should also pay attention to add the appropriate permissions, such as the use of communication needs to join in Androidmanifest.xml, and switch Bluetooth needs android.permission.BLUETOOTH_ Admin permissions.As
Android 4.3 (API level 18) has started to introduce the core features of Bluetooth low energy (BLE, Bluetooth) and provides APIs that enable applications to scan devices, query services, The characteristics (attribute feature) of the read-write device. Compared to traditional Bluetooth, BLE is designed to significantly
);}
2. Find a device
By using the thadapter class, you can search for remote devices (less than 10 meters) or other devices that have been matched (or bound) on your mobile phone. Of course, make sure that the bluetooth device of the other party has enabled or enabled the "Discovery enable" function (the other party's device can be found on the premise that you can initiate a connection ). If the device can be found, some device information of the oth
If the local Bluetooth device can be found by other nearby bluetooth devices, you can use the following method with comments in the code.
Of course, you need to set up your Bluetooth device to be detected by nearby bluetooth devices (usually 2 minutes)
In settings-Bluetooth-
void OnClick (View v) {
//Get Bluetoothadapter object, this API is supported by Android 2.0
Bluetoothadapter adapter = Bluetoothadapter.getdefaultadapter ();
//adapter is not equal to NULL, indicating that this machine has a Bluetooth device
if (adapter! = null) {
System.out.println ("This machine has Bluetooth device!");
//If the
(1) If you want to use the Bluetooth Android phone, you need to add Bluetooth access to the Androidmanifest file.Note: Permissions should be added to the Androidmanifest file (2) to determine if there is a Bluetooth device that can be used, if there is to determine whether the Bluetooth device is turned on, if not open
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.