get Bluetooth Address - Android android.bluetooth

Android examples for android.bluetooth:Bluetooth Address

Description

get Bluetooth Address

Demo Code

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;

public class Main{

    public static final int REQUEST_ENABLE_BT = 3;

    public static String getBluetoothAddress(boolean openOrNot,
            Activity activity) {/*from   ww  w  . ja  v  a  2s .  co m*/
        String btMac = "";

        BluetoothAdapter bAdapt = BluetoothAdapter.getDefaultAdapter();

        if (bAdapt != null) {
            if (openOrNot && !bAdapt.isEnabled()) {
                Intent enBT = new Intent(
                        BluetoothAdapter.ACTION_REQUEST_ENABLE);
                activity.startActivityForResult(enBT, REQUEST_ENABLE_BT);
            }

            btMac = bAdapt.getAddress();
        }

        return btMac;
    }

}

Related Tutorials