Example usage for android.bluetooth BluetoothAdapter getRemoteDevice

List of usage examples for android.bluetooth BluetoothAdapter getRemoteDevice

Introduction

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

Prototype

public BluetoothDevice getRemoteDevice(byte[] address) 

Source Link

Document

Get a BluetoothDevice object for the given Bluetooth hardware address.

Usage

From source file:org.mobisocial.corral.CorralClient.java

private Uri getFileOverBluetooth(DbUser user, SignedObj obj) throws IOException {
    String macStr = DbContactAttributes.getAttribute(mContext, user.getLocalId(), Contact.ATTR_BT_MAC);
    if (macStr == null) {
        throw new IOException("No bluetooth mac address for user");
    }/*  w  w  w. j a  v  a 2 s  .c o m*/
    String uuidStr = DbContactAttributes.getAttribute(mContext, user.getLocalId(), Contact.ATTR_BT_CORRAL_UUID);
    if (uuidStr == null) {
        throw new IOException("No corral uuid for user");
    }
    UUID uuid = UUID.fromString(uuidStr);
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    BluetoothDevice device = adapter.getRemoteDevice(macStr);
    BluetoothSocket socket;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
        socket = device.createInsecureRfcommSocketToServiceRecord(uuid);
    } else {
        socket = device.createRfcommSocketToServiceRecord(uuid);
    }

    // TODO:
    // Custom wire protocol, look for header bits to map to protocol handler.
    Log.d(TAG, "BJD BLUETOOTH CORRAL NOT READY: can't pull file over bluetooth.");
    return null;
}

From source file:com.rosterloh.moodring.profile.BleProfileService.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS))
        throw new UnsupportedOperationException("No device address at EXTRA_DEVICE_ADDRESS key");

    final Uri logUri = intent.getParcelableExtra(EXTRA_LOG_URI);
    mDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);

    Log.i(TAG, "Service started");

    // notify user about changing the state to CONNECTING
    final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
    broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_CONNECTING);
    LocalBroadcastManager.getInstance(BleProfileService.this).sendBroadcast(broadcast);

    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
    final BluetoothAdapter adapter = bluetoothManager.getAdapter();
    final BluetoothDevice device = adapter.getRemoteDevice(mDeviceAddress);
    mDeviceName = device.getName();//from w  w w . j  a v a 2s . c  o m
    onServiceStarted();

    Log.v(TAG, "Connecting...");
    mBleManager.connect(BleProfileService.this, device);
    return START_REDELIVER_INTENT;
}

From source file:com.example.RITW.Ble.BleProfileService.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS))
        throw new UnsupportedOperationException("No device address at EXTRA_DEVICE_ADDRESS key");

    final Uri logUri = intent.getParcelableExtra(EXTRA_LOG_URI);
    //      mLogSession = Logger.openSession(getApplicationContext(), logUri);
    mDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);

    //      Logger.i(mLogSession, "Service started");

    // notify user about changing the state to CONNECTING
    final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
    broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_CONNECTING);
    LocalBroadcastManager.getInstance(BleProfileService.this).sendBroadcast(broadcast);

    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
    final BluetoothAdapter adapter = bluetoothManager.getAdapter();
    final BluetoothDevice device = adapter.getRemoteDevice(mDeviceAddress);
    mDeviceName = device.getName();// www.  j ava  2s.  c  om
    onServiceStarted();

    //      Logger.v(mLogSession, "Connecting...");
    mBleManager.connect(BleProfileService.this, device);
    return START_REDELIVER_INTENT;
}

From source file:no.android.proxime.profile.BleProfileService.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS))
        throw new UnsupportedOperationException("No device address at EXTRA_DEVICE_ADDRESS key");

    final Uri logUri = intent.getParcelableExtra(EXTRA_LOG_URI);
    mLogSession = Logger.openSession(getApplicationContext(), logUri);
    mDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);

    Logger.i(mLogSession, "Service started");

    // notify user about changing the state to CONNECTING
    final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
    broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_CONNECTING);
    LocalBroadcastManager.getInstance(BleProfileService.this).sendBroadcast(broadcast);

    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
    final BluetoothAdapter adapter = bluetoothManager.getAdapter();
    final BluetoothDevice device = adapter.getRemoteDevice(mDeviceAddress);
    mDeviceName = device.getName();/* w w w  .j a v a  2  s .c  o m*/
    onServiceStarted();

    Logger.v(mLogSession, "Connecting...");
    mBleManager.connect(BleProfileService.this, device);
    return START_REDELIVER_INTENT;
}

From source file:com.diy.blelib.profile.BleProfileService.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS))
        throw new UnsupportedOperationException("No device address at EXTRA_DEVICE_ADDRESS key");

    mDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);
    Log.i(TAG, "Service started");
    //?????/* w  ww .  j  av a 2s . co  m*/
    if (!mBlutoothAdapter.isEnabled())
        mBlutoothAdapter.enable();
    // notify user about changing the state to CONNECTING
    final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
    broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_CONNECTING);
    LocalBroadcastManager.getInstance(BleProfileService.this).sendBroadcast(broadcast);

    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
    final BluetoothAdapter adapter = bluetoothManager.getAdapter();
    final BluetoothDevice device = adapter.getRemoteDevice(mDeviceAddress);
    mDeviceName = device.getName();
    onServiceStarted();

    Log.v(TAG, "Connecting...");
    mBleManager.connect(BleProfileService.this, device);
    return START_REDELIVER_INTENT;
}

From source file:com.authorwjf.bounce.BluetoothChat.java

private void setupChat() {
    // Initialize the array adapter for the conversation thread
    mConversationArrayAdapter = new ArrayAdapter<String>(this, R.layout.message);

    // Initialize the BluetoothChatService to perform bluetooth connections
    mChatService = new BluetoothChatService(this, mHandler);

    // Initialize the buffer for outgoing messages
    mOutStringBuffer = new StringBuffer("");

    BluetoothAdapter myAdapter = BluetoothAdapter.getDefaultAdapter();

    BluetoothDevice remoteDevice = myAdapter.getRemoteDevice(Main.macAddress);

    try {/* w w  w .j  a  v a 2s. co m*/
        BluetoothSocket btSocket = remoteDevice
                .createRfcommSocketToServiceRecord(BluetoothChatService.MY_UUID_INSECURE);
        btSocket.connect();
    } catch (IOException exc) {
        System.out.println("Error connecting");
        stopSelf();
    }
    new AutomaticQueryThread(mSendButton, this).start();
}

From source file:org.envirocar.app.application.service.BackgroundServiceImpl.java

private void startBluetoothConnection() {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    String remoteDevice = preferences.getString(SettingsActivity.BLUETOOTH_KEY, null);
    // Stop if device is not available

    if (remoteDevice == null || "".equals(remoteDevice)) {
        return;/* ww  w .  j  a v  a2s . c  om*/
    }

    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    BluetoothDevice bluetoothDevice = bluetoothAdapter.getRemoteDevice(remoteDevice);

    bluetoothConnection = new BluetoothConnection(bluetoothDevice, true, this, getApplicationContext());
}

From source file:org.mobisocial.corral.CorralDownloadClient.java

private Uri getFileOverBluetooth(DbIdentity user, SignedObj obj, CorralDownloadFuture future,
        DownloadProgressCallback callback) throws IOException {
    callback.onProgress(DownloadState.PREPARING_CONNECTION, DownloadChannel.BLUETOOTH, 0);
    String macStr = DbContactAttributes.getAttribute(mContext, user.getLocalId(),
            DbContactAttributes.ATTR_BT_MAC);
    if (macStr == null) {
        throw new IOException("No bluetooth mac address for user");
    }//from  w  w  w . j av a 2 s.co m
    String uuidStr = DbContactAttributes.getAttribute(mContext, user.getLocalId(),
            DbContactAttributes.ATTR_BT_CORRAL_UUID);
    if (uuidStr == null) {
        throw new IOException("No corral uuid for user");
    }
    UUID uuid = UUID.fromString(uuidStr);
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    BluetoothDevice device = adapter.getRemoteDevice(macStr);
    BluetoothSocket socket;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
        socket = device.createInsecureRfcommSocketToServiceRecord(uuid);
    } else {
        socket = device.createRfcommSocketToServiceRecord(uuid);
    }

    // TODO:
    // Custom wire protocol, look for header bits to map to protocol handler.
    Log.d(TAG, "BJD BLUETOOTH CORRAL NOT READY: can't pull file over bluetooth.");
    return null;
}

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

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

    listAdapter.clear();//from   ww w  .j  a  v a 2  s. c  om
    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);
        }
    }
}

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.");
    }//  w  ww  . j a v  a  2  s .  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());
        }
    }
}