The RemoteDevice class represents a Bluetooth device with a certain address. Such devices may or may not be accessible at any given time. They are remote, so they can crash, move, be turned off, run out of battery power, or otherwise disappear from view independently of the local system. There is one protected constructor in this class:
protected RemoteDevice(String address)
However, it is not normally used. Instead, you discover devices as explained in the previous section. If you already have an open connection to the device you want to query, you can use the static RemoteDevice.getRemoteDevice( ) method to retrieve the RemoteDevice object representing the actual device:
public static RemoteDevice getRemoteDevice(Connection conn) throws IOException
Youve now found the remote devices. What are you going to do with them? Of course, this depends on the type of the device. The RemoteDevice class tells you this. Although LocalDevice and RemoteDevice do not have a common superclass, they do share many methods that do pretty much the same thing. There is, however, one crucial difference: queries to the remote device go out over the air whereas queries to the local device stay within the system. This means remote queries are slower, less secure, and less reliable than local queries.
The getBluetoothAddress( ) method returns a String containing the 12-hex-digit Bluetooth address of the controller:
public final String getBluetoothAddress( )
The getFriendlyName( ) method returns a more human-legible name:
public String getFriendlyName( ) throws IOException
Bluetooth connections can be authorized, authenticated, and/or encrypted, though not all devices support all these options. The latter is particularly uncommon because of the CPU cost of high-quality encryption. Nonetheless, the RemoteDevice class provides methods to inquire whether any particular connection is authorized, authenticated, or encrypted and to request such services.
A device is authenticated if it has successfully exchanged a 128-bit key with the host. Normally this requires entering the same PIN code on both the host and the device. The host or device may randomly generate a key and corresponding PIN and ask you to enter it on the other end of the connection. Java programs use the Bluetooth Control Center to do this. The isAuthenticated( ) method returns true if the device is authenticated and false if it isn :
public boolean isAuthenticated( )
The authenticate( ) method attempts to authenticate a device by exchanging the secret key derived from the shared PIN code:
public boolean authenticate( ) throws IOException
This method returns TRue if authentication succeeds and false if it doesn . It throws an IOException if theres no current connection between the local and the remote device. Authentication needs to be performed only once per device. After a device has successfully authenticated, all further connections are automatically authenticated.
A device is authorized if the user has given permission for this remote device to use the local service. The isAuthorized( ) method returns true if the device is authorized and false if it isn :
public boolean isAuthorized( )
The authorize( ) method asks the user to authorize the device for a particular connection:
public boolean authorize(Connection conn) throws IOException
This method returns TRue if authorization succeeds and false if it doesn . It throws an IOException if theres no current connection between the local and remote devices. Authentication is a prerequisite for authorization. Before authorizing, this device attempts to authenticate itself.
Some devices can be permanently authorized. Such devices are called trusted. Java programs use the Bluetooth Control Center to identify a device as trusted. The isTrustedDevice( ) returns TRue if the device is trusted and false if it isn :
public boolean isTrustedDevice( )
Finally, a few devices support encrypted communication. The isEncrypted( ) method returns TRue if the device encrypts connections and false if it doesn :
public boolean isAuthenticated( )
The encrypt( ) method instructs a device to turn encryption on or off:
public boolean encrypt(Connection conn, boolean on) throws IOException
This method returns true if the device is now in encrypted mode and false if it isn .
Streams in Memory
The File System
Working with Files
File Dialogs and Choosers
Character Sets and Unicode
Readers and Writers
Formatted I/O with java.text
The Java Communications API
The J2ME Generic Connection Framework
Authors: Elliotte Rusty Harold
Similar book on Amazon