Example usage for android.bluetooth BluetoothDevice getAddress

List of usage examples for android.bluetooth BluetoothDevice getAddress

Introduction

In this page you can find the example usage for android.bluetooth BluetoothDevice getAddress.

Prototype

public String getAddress() 

Source Link

Document

Returns the hardware address of this BluetoothDevice.

Usage

From source file:Main.java

public static String deviceId(BluetoothDevice device) {
    return device.getAddress();
}

From source file:Main.java

public static BluetoothDevice getDevice(BluetoothAdapter bluetoothAdapter) {
    BluetoothDevice innerprinter_device = null;
    Set<BluetoothDevice> devices = bluetoothAdapter.getBondedDevices();
    for (BluetoothDevice device : devices) {
        if (device.getAddress().equals(Innerprinter_Address)) {
            innerprinter_device = device;
            break;
        }/* w  ww .  j  a va  2 s. com*/
    }
    return innerprinter_device;
}

From source file:Main.java

public static String printDevice(BluetoothDevice device) {
    return String.format("%s; %s; %s; %s", device.getAddress(), device.getName(), device.getType(),
            device.getBluetoothClass());
}

From source file:Main.java

private static String convertBluetoothDevice(BluetoothDevice device) {
    String list;/* ww w  . j av a  2  s  .  c om*/
    list = "Address: " + device.getAddress();
    list += ", Name: " + device.getName();
    list += ", Class: " + device.getBluetoothClass();
    list += ", State: " + device.getBondState();
    list += "\n\n";
    return list;
}

From source file:Main.java

public static byte[] getByteAddress(BluetoothDevice device) {
    return getBytesFromAddress(device.getAddress());
}

From source file:Main.java

public static BluetoothDevice getDeviceByAddress(String address) {
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    for (BluetoothDevice device : mBluetoothAdapter.getBondedDevices()) {
        if (device.getAddress().equals(address)) {
            return device;
        }/*from  w  w w  .  j av a 2s  . c  o  m*/
    }

    return null;
}

From source file:Main.java

public static void unpairMac(String macToRemove) {
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    Set<BluetoothDevice> bondedDevices = bluetoothAdapter.getBondedDevices();
    try {/*from  w  ww . j av a 2 s .  c o  m*/
        Class<?> btDeviceInstance = Class.forName(BluetoothDevice.class.getCanonicalName());
        Method removeBondMethod = btDeviceInstance.getMethod("removeBond");
        boolean cleared = false;
        for (BluetoothDevice bluetoothDevice : bondedDevices) {
            String mac = bluetoothDevice.getAddress();
            if (mac.equals(macToRemove)) {
                removeBondMethod.invoke(bluetoothDevice);
                Log.i(TAG, "Cleared Pairing");
                cleared = true;
                break;
            }
        }

        if (!cleared) {
            Log.i(TAG, "Not Paired");
        }
    } catch (Throwable th) {
        Log.e(TAG, "Error pairing", th);
    }
}

From source file:Main.java

/**
 * Turns the #BluetoothDevice into a human-readable string.
 */// w  ww  . ja  v a  2 s  .com
public static String getDisplayString(BluetoothDevice device) {
    String name = device.getName();
    String address = device.getAddress();

    if (name == null)
        return address;

    return name + " [" + address + "]";
}

From source file:co.aurasphere.bluepair.bluetooth.BluetoothController.java

/**
 * Converts a BluetoothDevice to its String representation.
 *
 * @param device the device to convert to String.
 * @return a String representation of the device.
 *///  w w  w .j a  v  a2 s.  c  o  m
public static String deviceToString(BluetoothDevice device) {
    return "[Address: " + device.getAddress() + ", Name: " + device.getName() + "]";
}

From source file:co.aurasphere.bluepair.bluetooth.BluetoothController.java

/**
 * Gets the name of a device. If the device name is not available, returns the device address.
 *
 * @param device the device whose name to return.
 * @return the name of the device or its address if the name is not available.
 *//*from   w ww  .  j  a  va  2 s  .  c  o  m*/
public static String getDeviceName(BluetoothDevice device) {
    String deviceName = device.getName();
    if (deviceName == null) {
        deviceName = device.getAddress();
    }
    return deviceName;
}