get Bluetooth Device Id - Android Bluetooth

Android examples for Bluetooth:Bluetooth Device

Description

get Bluetooth Device Id

Demo Code


//package com.java2s;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;

public class Main {
    public static int getDeviceId(BluetoothDevice device) {
        return getDeviceId(device.getAddress());
    }// w w w .  j a  v a 2s . c  o  m

    public static int getDeviceId(String address) {
        if (!BluetoothAdapter.checkBluetoothAddress(address)) {
            return 0;
        }

        final String longAddress = address.replaceAll(":", "");
        return (int) (Long.parseLong(longAddress, 16));
    }
}

Related Tutorials