Example usage for android.bluetooth BluetoothAdapter checkBluetoothAddress

List of usage examples for android.bluetooth BluetoothAdapter checkBluetoothAddress

Introduction

In this page you can find the example usage for android.bluetooth BluetoothAdapter checkBluetoothAddress.

Prototype

public static boolean checkBluetoothAddress(String address) 

Source Link

Document

Validate a String Bluetooth address, such as "00:43:A8:23:10:F0"

Alphabetic characters must be uppercase to be valid.

Usage

From source file:Main.java

public static boolean isValidAddress(String address) {
    return BluetoothAdapter.checkBluetoothAddress(address);
}

From source file:Main.java

public static String validateBluetoothAddress(String address) {
    if (BluetoothAdapter.checkBluetoothAddress(address)) {
        return address;
    } else {//from ww w  . j  ava2 s . c o m
        StringBuilder buf = new StringBuilder(17);
        buf.append(address.toUpperCase());

        buf.insert(2, ':');
        buf.insert(5, ':');
        buf.insert(8, ':');
        buf.insert(11, ':');
        buf.insert(14, ':');

        return buf.toString();
    }
}

From source file:Main.java

private static Pair<String, String> getAddressVersion0(Uri uri) {
    final String path = uri.getPath();
    if ((path == null) || (path.length() <= 1)) {
        // Missing address.
        return null;
    }/* w  ww  .j  av a 2s.co  m*/

    final String address = path.substring(1);
    if (!BluetoothAdapter.checkBluetoothAddress(address)) {
        // Invalid address.
        return null;
    }

    return new Pair<String, String>(address, null);
}

From source file:com.netlinks.healthbracelet.service.HeartRateService.java

/**
 * Bluetooth Configuration//from w w  w .  j  av a2 s.c  o  m
 * 1- Establishing the connection with the bracelet
 * 2- Create the socket
 */

public void BluetoothConfig() {
    final String address = "04:1B:BA:97:1A:33"; //Health Bracelet MAC address

    // If the adapter is null, then Bluetooth is not supported
    if (mAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        stopSelf();
        return;
    } else {
        if (mAdapter.isEnabled()) {
            Log.d(TAG, "...Bluetooth is ON...");
        } else {
            Log.d(TAG, "...Bluetooth is OFF...");
            //TODO Requesting to open bluetooth (in a proper way)
            Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            enableBtIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            //int REQUEST_ENABLE_BT = 404;
            getApplication().startActivity(enableBtIntent);

        }
    }

    Log.d(TAG, "...trying to connect...");

    if (!BluetoothAdapter.checkBluetoothAddress(address)) {
        Log.d(TAG, "Fatal Error : Incorrect MAC-address");
    } else {
        // Set up a pointer to the remote node using it's address.
        final BluetoothDevice device = mAdapter.getRemoteDevice(address);

        if (mState != STATE_CONNECTED) {
            this.connect(device);
        }

    }
}

From source file:org.da_cha.android.bluegnss.MainFragment.java

private void setBluetoothDeviceName(View v) {
    Log.v(LOG_TAG, "entered setBluetoothDeviceName()");
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    String deviceAddress = sharedPref.getString(GnssProviderService.PREF_BLUETOOTH_DEVICE, null);
    if (deviceAddress == null) {
        Log.d(LOG_TAG, "setBluetoothDeviceName(): deviceAddress is null.");
    }//from  ww w .  j  a va  2s.  c  o  m
    TextView txtDeviceName = (TextView) v.findViewById(R.id.main_bluetooth_device_name);
    if (bluetoothAdapter != null) {
        if (BluetoothAdapter.checkBluetoothAddress(deviceAddress)) {
            txtDeviceName.setText(bluetoothAdapter.getRemoteDevice(deviceAddress).getName());
        }
    }
}

From source file:com.pairbluetooth.mariachiio.dagorik.pairbluetooth.test_bluetooth.test_bluetooth.utils.BlueDroid.java

private void connect(String address) {
    Log.d(TAG, "BlueDroid.connect(" + address + ")");
    if (isConnecting) {
        return;// www  .  ja  v  a 2 s.  co  m
    }
    if (!isServiceAvailable()) {
        setupService();
    }

    startService();

    if (BluetoothAdapter.checkBluetoothAddress(address)) {
        BluetoothDevice device = mBtAdapter.getRemoteDevice(address);
        mBtService.connect(device);
    }
}

From source file:com.ec.android.module.bluetooth40.BluetoothLeService.java

/**
 * Connects to the GATT server hosted on the Bluetooth LE device.
 *
 * @param address The device address of the destination device.
 * @return Return true if the connection is initiated successfully. The connection result
 * is reported asynchronously through the
 * {@code BluetoothGattCallback#onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)}
 * callback./* www .  j av a 2 s. c o m*/
 */
public boolean connect(final String address) {
    if (mBluetoothAdapter == null || address == null) {
        Log.w(TAG, "BluetoothAdapter not initialized or unspecified address.");
        return false;
    }
    //address??mac??
    if (!BluetoothAdapter.checkBluetoothAddress(address)) {
        Log.w(TAG, "address??mac??");
        return false;
    }
    ////FIXME
    /*if (mBluetoothGatt != null) {
    disconnect();
    close();
    }*/
    if (mBluetoothGatt != null && mBluetoothManager != null) {
        BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
        int connectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT);

        if (connectionState == BluetoothGatt.STATE_CONNECTED) {
            //
            if (DEBUG) {
                Toast.makeText(getApplicationContext(), "?", Toast.LENGTH_SHORT)
                        .show();
            }
            Log.d(TAG, "?");
            return false;
        }
    }
    ////
    // Previously connected device.  Try to reconnect.
    if (mBluetoothDeviceAddress != null && address.equals(mBluetoothDeviceAddress) && mBluetoothGatt != null) {
        Log.d(TAG, "Trying to use an existing mBluetoothGatt for connection.");
        if (mBluetoothGatt.connect()) {
            mConnectionState = STATE_CONNECTING;
            return true;
        } else {
            return false;
        }
    }
    //
    final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
    if (device == null) {
        Log.w(TAG, "Device not found.  Unable to connect.");
        return false;
    }
    // We want to directly connect to the device, so we are setting the autoConnect
    // parameter to false.
    mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
    Log.d(TAG, "Trying to create a new connection.");
    mBluetoothDeviceAddress = address;
    mConnectionState = STATE_CONNECTING;
    return true;

}

From source file:com.pileproject.drive.setting.machine.BluetoothMachineSelectFragment.java

private void updatePairedList() {
    BluetoothMachineListAdapter listAdapter = (BluetoothMachineListAdapter) mPairedDevicesListView.getAdapter();
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    listAdapter.clear();/*ww w .j a  v  a  2 s.co  m*/
    listAdapter.addAll(bluetoothAdapter.getBondedDevices());

    String macAddress = MachinePreferences.get(getActivity()).getMacAddress();

    if (BluetoothAdapter.checkBluetoothAddress(macAddress)) {
        BluetoothDevice device = bluetoothAdapter.getRemoteDevice(macAddress);

        if (listAdapter.contains(device)) {
            mPairedDevicesListView.setItemChecked(listAdapter.getPosition(device), true);
        }
    }
}