FileDocCategorySizeDatePackage
NativeBCC.javaAPI DocphoneME MR2 API (J2ME)9669Wed May 02 18:00:32 BST 2007com.sun.kvem.jsr082.bluetooth

NativeBCC

public class NativeBCC extends BCC
Native-based Bluetooth Control Center. For many operations, this implementation relies on BluetoothStack class.

Fields Summary
private final char
ADDR_DELIMETER
Delimiter character used to separate entries in packed strings returned by getPreknown().
Constructors Summary
protected NativeBCC()
Constructs the only instance of this class.



                
      
        initialize();
    
Methods Summary
public booleanauthenticate(java.lang.String address)
Authenticates remote device.

param
address Bluetooth address of a remote device
return
true if the device was authenticated, false otherwise

        if (isAuthenticated(address)) {
            return true;
        }
        if (!isPaired(address)) {
            String pin = getPasskey(address);
            if (pin == null || !bond(address, pin)) {
                return false;
            }
        }

        return BluetoothStack.getInstance().authenticateSync(address);
    
public native booleanauthorize(java.lang.String address, int handle)
Authorizes a Bluetooth connection.

param
address Bluetooth address of a remote device
param
handle handle for the service record of the srvice the remote device is trying to access
return
true if authorization succeeded, false otherwise

public native booleanbond(java.lang.String address, java.lang.String pin)
Initiates pairing with a remote device.

param
address the Bluetooth address of the device with which to pair
param
pin an array containing the PIN code
return
true if the device was authenticated, false otherwise

public native booleanconfirmEnable()
Asks user whether Bluetooth radio is allowed to be turned on.

return
true if user has allowed to enable Bluetooth, false otherwise

public booleanenableBluetooth()
Enables Bluetooth radio and the Bluetooth protocol stack for use.

return
true if the operation succeeded, false otherwise

        if (BluetoothStack.getInstance().isEnabled()) {
            return true;
        }
        if (!confirmEnable()) {
            return false;
        }
        return BluetoothStack.getInstance().enable();
    
public booleanencrypt(java.lang.String address, boolean enable)
Enables or disables encryption of data exchanges.

param
address the Bluetooth address of the remote device
param
enable indicated whether the encryption needs to be enabled
return
true if the encryption has been changed, false otherwise

        if (setEncryption(address, enable)) {
            return BluetoothStack.getInstance().encryptSync(address, enable);
        }
        return false;
    
private native voidfinalize()
Releases native resources.

public intgetAccessCode()

        return BluetoothStack.getInstance().getAccessCode();
    
public java.lang.StringgetBluetoothAddress()
Returns local Bluetooth address.

return
local Bluetooth address.

        return BluetoothStack.getInstance().getLocalAddress();
    
public DeviceClassgetDeviceClass()

        return new DeviceClass(BluetoothStack.getInstance().getDeviceClass());
    
public java.lang.StringgetFriendlyName(java.lang.String address)
Retrieves the user-friendly name for specified remote device.

param
address Bluetooth address of a remote device
return
name of the remote device, or null if the name could not be retrieved
see
RemoteDevice#getFriendlyName

        return BluetoothStack.getInstance().askFriendlyNameSync(address);
    
public java.lang.StringgetFriendlyName()
Returns user-friendly name for the local device.

return
user-friendly name for the local device, or null if the name could not be retrieved
see
LocalDevice#getFriendlyName

        return BluetoothStack.getInstance().getLocalName();
    
public native java.lang.StringgetPasskey(java.lang.String address)
Retrieves PIN code to use for pairing with a remote device. If the PIN code is not known, PIN entry dialog is displayed.

param
address the Bluetooth address of the remote device
return
string containing the PIN code

private native java.lang.StringgetPreknown()
Returns list of preknown devices in a packed string.

return
packed string containing preknown devices

public java.util.VectorgetPreknownDevices()
Returns list of preknown devices in a packed string.

return
vector containing preknown devices

        return listDevices(getPreknown());
    
private native voidinitialize()
Allocates native resources.

public native booleanisAuthenticated(java.lang.String address)
Checks if a remote device was authenticated.

param
address Bluetooth address of a remote device
return
true if the device was authenticated, false otherwise

public booleanisBluetoothEnabled()
Queries the power state of the Bluetooth device.

return
true is the Bluetooth device is on, false otherwise.

        return BluetoothStack.getInstance().isEnabled();
    
public native booleanisConnectable()
Determines if the local device is in connectable mode.

return
true if the device is connectable, false otherwise

public native booleanisConnected(java.lang.String address)
Checks if there is a connection to the remote device.

param
address the Bluetooth address of the remote device
return
true if connection is established with the remote device

public native booleanisEncrypted(java.lang.String address)
Checks if connections to a remote device are encrypted.

param
address Bluetooth address of the remote device
return
true if connections to the device are encrypted, false otherwise

public native booleanisPaired(java.lang.String address)
Checks if the local device has a bond with a remote device.

param
address Bluetooth address of a remote device
return
true if the two devices were paired, false otherwise

public native booleanisTrusted(java.lang.String address)
Checks if a remote device is trusted (authorized for all services).

param
address Bluetooth address of a remote device
return
true if the device is trusted, false otherwise

private java.util.VectorlistDevices(java.lang.String packed)
Extracts Bluetooth addresses from a packed string. In the packed string, each device entry is a Bluetooth device address followed by ADDR_DELIMETER delimiter.

param
packed string containing Bluetooth addresses
return
Vector containing Bluetooth addresses

        if (packed == null || packed.trim().length() == 0) {
            return null;
        }

        Vector addrs = new Vector();
        int index = 0;
        while (index < packed.length()) {
            int end = packed.indexOf(ADDR_DELIMETER, index);
            if (end == -1) {
                end = packed.length();
            }
            addrs.addElement(packed.substring(index, end));
            index = end + 1;
        }
        return addrs;
    
public booleansetAccessCode(int accessCode)

        return BluetoothStack.getInstance().setAccessCode(accessCode);
    
public native booleansetEncryption(java.lang.String address, boolean enable)
Increases or decreases encryption request counter for a remote device.

param
address the Bluetooth address of the remote device
param
enable indicated whether the encryption needs to be enabled
return
true if the encryption needs to been changed, false otherwise

public booleansetServiceClasses(int classes)

        return BluetoothStack.getInstance().setServiceClasses(classes);