Android Bluetooth Stack bluez usage

Source: Internet
Author: User

Many developers use the latest Android 0.9
No reference for the Bluetooth Stack is found in the SDK. However, in the official message, we have seen that the package related to org. bluez is used. Here we will introduce Android blue
For the SDP-related routine, we can see that it is. Intent. Action, which is divided into four stages:

Org. bluez. Intent. Action. discovery_started
Org. bluez. Intent. Action. remote_device_found
Remote device found
Org. bluez. Intent. Action. remote_name_updated
Org. bluez. Intent. Action. discovery_completed
Complete SDP

The general usage method is as follows. You can test it on the Development Board. First, port the org. bluez library.

Public void onstart (INT startid, bundle ARGs)
{

Super. onstart (startid, argS );
Try {

Iblustmthservice ibtservice =
Descrithservicenative. getgatethservice ();
// Obtain an instance. In fact, the system service is ready in Android.
If (ibtservice = NULL)
{
Stopself (); // if it fails, exit

Return;
}


Manager = ibtservice. getmanager ();
If (Manager = NULL)
{
Stopself ();
}


If (! Ibtservice. isw.thstarted ()){

Ibtservice. startbluetooth (); // start the service
}

Miadapter = manager. getdefaadapter adapter ();

Miadapter. startdiscovery (); // you have prepared for the probe.


String [] dispositivos = miadapter. listremotedevices (); // remote device Mac list


If (dispositivos. Length = 0 ){

Toast. maketext (this, R. String. no_found_devices,
Toast. length_short). Show (); // No bluetooth device found
} Else {

For (INT I = 0; I <dispositivos. length; I ++ ){

// For a bluetooth device that has been found, prepare for pairing and perform the matching on your own. Of course, for example, you can determine whether the device type is handset, FTP, or another device type based on Mac. Of course, the standard is true.
Gps uses the serial port for communication.
}
}

} Catch (exception e ){

System. Out. println (E. getmessage ());
}
}

After opening the communication, you can import the following classes.

Import org. bluez. Manager;
Import org. bluez. Adapter;
Import
Org. bluez. ibluw.thservice;
Import org. bluez. descrithservicenative;

Let's talk about the specific Android Bluetooth Stack later.

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.