Android Bluetooth Development (ii): Introduction to related APIs

Source: Internet
Author: User

One, bluetoothadapter--Bluetooth adapter (native)

There are many methods in Bluetoothadapter, commonly used are the following:

(1) canceldiscovery () by literal means, is to cancel the discovery, that is, when we are searching the device, call this method will not continue to search

(2) Disable () Turn off Bluetooth

(3) Enable () Turn on Bluetooth, this method to turn on Bluetooth will not pop up the prompt,

More time we need to ask if the user is open, the following two lines of code is also open Bluetooth, but will prompt the user:

Intent enableintent = new Intent (bluetoothadapter.action_request_enable);
Startactivityforresult (Enableintent, REQUEST_ENABLE_BT);//can also be written startactivity (enableintent);

(4) getaddress () get local Bluetooth address

(5) Getdefaultadapter () Gets the default Bluetoothadapter, in fact, there is only one way to get Bluetoothadapter

(6) GetName () get the local Bluetooth name

(7) Getremotedevice (String address) to obtain a remote Bluetooth device based on the Bluetooth location

(8) GetState () Gets the current status of the local Bluetooth adapter (more needed when it feels possible to debug)

(9) Isdiscovering () to determine whether the device is currently being looked up, is true

() isenabled () to determine if Bluetooth is turned on, turned on returns True, otherwise, returns false

(one) Listenusingrfcommwithservicerecord (String name,uuid uuid) by name, UUID creates and returns Bluetoothserversocket, This is the first step in creating a Bluetoothsocket server side

StartDiscovery () Start search, this is the first step in searching

Second, bluetoothdevice--Bluetooth device (remote)

Createrfcommsockettoservicerecord (UUIDUUID) creates and returns a bluetoothsocket based on the UUID

This approach is also the purpose of our acquisition of Bluetoothdevice-creating Bluetoothsocket

Other methods of this class, such as GetAddress (), GetName (), with Bluetoothadapter

Three, bluetoothsocket--Bluetooth socket interface

Iv. bluetoothserversocket--represents an open server socket that listens for incoming connection requests

Five, Bluetooth package also has 4 classes, Bluetoothclass, Bluetoothclass.device, BluetoothClass.Device.Major, Bluetoothclass.service

Android Bluetooth Development (ii): Introduction to related APIs

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.