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.