Hardware Reference
In-Depth Information
Toast . makeText ( this , msg , Toast . LENGTH_SHORT ). show ();
Log . d ( "DEBUG" , "uiDeviceFound: " + msg );
}
}
This code posts a toast message box whenever it finds a device. It's not very practical,
but it's an easy way to indicate when a device is found and display information about
the device. In a real use case, you'd be outputting any found devices to a device list that
people could click to initiate a connection.
The toast message displays two pieces of information from the advertising packet: the
device name (see “Advertising Data Format” on page 48 ) and the RSSI. RSSI (a wireless
term that stands for received signal strength indicator ) is a way to indicate how strong
the received signal (in this case the average of all the bits contained in the advertising
packet) is. In some cases, the RSSI can be used to give a rough approximation of distance.
Another key piece of information that would likely be useful is the device address (which
is included with every advertising packet), but the device name alone is fine for now.
The code not only outputs the same information to the toast messagebox, but it also
logs it via the Log command, which is an Android library. The Log messages show up
in the Eclipse IDE during debug using the logcat tool (shown in Figure 8-8 ). When
you use the Log command, you also specify a tag. The good thing about this is that you
can filter on the tag to remove extraneous information.
Figure 8-8. The message from the Log command highlighted in the full logcat informa‐
tion dump
By now, the code should have been able to verify that it could detect a remote device
sending advertising packets. Once it's able to do that, it needs to be able to connect to
it. Normally, you'd save all the detected devices and display them to the user in list form,
as explained in “Connection establishment procedures” on page 41 . The user would
 
Search WWH ::




Custom Search