String deviceName = "My_Device_Name"; BluetoothDevice result = null; Set<BluetoothDevice> devices = adapter.getBondedDevices(); if (devices != null) { for (BluetoothDevice device : devices) { if (deviceName.equals(device.getName())) { result = device; break; } } }
@Override @Nullable public String getName() { return bluetoothDevice.getName(); }
@Override public String toString() { return "RxBleDeviceImpl{" + "bluetoothDevice=" + bluetoothDevice.getName() + '(' + bluetoothDevice.getAddress() + ')' + '}'; } }
private void appendDeviceHeader(BluetoothDevice device, StringBuilder descriptionBuilder) { descriptionBuilder .append("--------------- ====== Printing peripheral content ====== ---------------\n") .append("PERIPHERAL ADDRESS: ").append(device.getAddress()).append('\n') .append("PERIPHERAL NAME: ").append(device.getName()).append('\n') .append("-------------------------------------------------------------------------"); }
BluetoothAdapter mBtAdapter = BluetoothAdapter.getDefaultAdapter(); Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices(); if (pairedDevices.size() > 0) { Toast.makeText(this, "At least one paired bluetooth device found", Toast.LENGTH_SHORT).show(); // TODO at this point you'd have to iterate these devices and check if any of them is a wearable (HOW?) for (BluetoothDevice device : pairedDevices) { Log.d("YOUR_TAG", "Paired device: "+ device.getName() + ", with address: " + device.getAddress()); } } else { Toast.makeText(this, "No paired bluetooth devices found", Toast.LENGTH_SHORT).show(); }
mBluetoothAdapter.startDiscovery(); mReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); //Finding devices if (BluetoothDevice.ACTION_FOUND.equals(action)) { // Get the BluetoothDevice object from the Intent BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); // Add the name and address to an array adapter to show in a ListView mArrayAdapter.add(device.getName() + "\n" + device.getAddress()); } } }; IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); registerReceiver(mReceiver, filter);
public BluetoothDeviceAssert hasName(String name) { isNotNull(); String actualName = actual.getName(); assertThat(actualName) // .overridingErrorMessage("Expected name <%s> but was <%s>.", name, actualName) // .isEqualTo(name); return this; }
protected static final UUID CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"); public boolean setCharacteristicNotification(BluetoothDevice device, UUID serviceUuid, UUID characteristicUuid, boolean enable) { if (IS_DEBUG) Log.d(TAG, "setCharacteristicNotification(device=" + device.getName() + device.getAddress() + ", UUID=" + characteristicUuid + ", enable=" + enable + " )"); BluetoothGatt gatt = mGattInstances.get(device.getAddress()); //I just hold the gatt instances I got from connect in this HashMap BluetoothGattCharacteristic characteristic = gatt.getService(serviceUuid).getCharacteristic(characteristicUuid); gatt.setCharacteristicNotification(characteristic, enable); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID); descriptor.setValue(enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[] { 0x00, 0x00 }); return gatt.writeDescriptor(descriptor); //descriptor write operation successfully started? }
if (!(mDeviceName.equals(scanRecord.getDeviceName()) || mDeviceName.equals(device.getName()))) { return false;
Log.d(TAG, mConnectedHeadset.getName() + " connected"); //$NON-NLS-1$
if (device != null) { macAddress = device.getAddress(); name = device.getName();
int i = 0; for (BluetoothDevice device : pairedDevices) { String name = MPGDeviceDetailsControl.getDeviceDetails(this, device.getAddress(), device.getName()).getDisplayName(); mPairedDevicesArrayAdapter.remove(name); // has to copy all items back 1 position mPairedDevicesArrayAdapter.insert(name + "\n" + device.getAddress(), i); // copy them +1 again i++; }
@Override public void run() { // always return a remote device BluetoothDevice remoteDevice = mBluetoothAdapter.getRemoteDevice(mac); mBluetoothAdapter.cancelDiscovery(); mCurrStatus = STATUS.FREE; try { Log.d(TAG, "prepare to connect: " + remoteDevice.getAddress() + " " + remoteDevice.getName()); // BluetoothSocket socket = remoteDevice.createRfcommSocketToServiceRecord(UUID.fromString(STR_UUID)); // BluetoothSocket socket = (BluetoothSocket) remoteDevice.getClass().getMethod("createRfcommSocket", new Class[] {int.class}).invoke(remoteDevice,1); mSocket = remoteDevice.createInsecureRfcommSocketToServiceRecord(UUID.fromString(Constants.STR_UUID)); // if(!socket.isConnected()) mSocket.connect(); mInputStream = mSocket.getInputStream(); mOutputStream = mSocket.getOutputStream(); mCurrStatus = STATUS.CONNECTED; } catch (Exception e) { if (listener != null) listener.onError(e); try { mInputStream.close(); mOutputStream.close(); } catch (IOException closeException) { closeException.printStackTrace(); } mCurrStatus = STATUS.FREE; } } }
/** * Gets the name. * * @return the name */ public String getName() { return mDevice.getName(); }
if(BluetoothDevice.ACTION_UUID.equals(action)) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); Parcelable[] uuidExtra = intent.getParcelableArrayExtra(BluetoothDevice.EXTRA_UUID); for (int i=0; i<uuidExtra.length; i++) { out.append("\n Device: " + device.getName() + ", " + device + ", Service: " + uuidExtra[i].toString()); }
private String getDeviceName(final BluetoothDevice device) { String name = device.getName(); if (TextUtils.isEmpty(name)) name = getString(R.string.proximity_default_device_name); return name; } }
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); // If there are paired devices if (pairedDevices.size() > 0) { // Loop through paired devices for (BluetoothDevice device : pairedDevices) { // Add the name and address to an array adapter to show in a ListView mArrayAdapter.add(device.getName() + "\n" + device.getAddress()); } }
@Override public void onScanResult(int callbackType, ScanResult result) { super.onScanResult(callbackType, result); if( result == null || result.getDevice() == null || TextUtils.isEmpty(result.getDevice().getName()) ) return; StringBuilder builder = new StringBuilder( result.getDevice().getName() ); builder.append("\n").append(new String(result.getScanRecord().getServiceData(result.getScanRecord().getServiceUuids().get(0)), Charset.forName("UTF-8"))); mText.setText(builder.toString()); }
@Override public void onLinkLossOccurred(final BluetoothDevice device) { if (mAdapter != null) mAdapter.onDeviceStateChanged(device); // The link loss may also be called when Bluetooth adapter was disabled if (BluetoothAdapter.getDefaultAdapter().isEnabled()) showLinkLossDialog(device.getName()); }
@Override protected void onStart() { super.onStart(); final Intent intent = getIntent(); if (!isDeviceConnected() && intent.hasExtra(FeaturesActivity.EXTRA_ADDRESS)) { final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); final BluetoothDevice device = bluetoothAdapter.getRemoteDevice(getIntent().getByteArrayExtra(FeaturesActivity.EXTRA_ADDRESS)); onDeviceSelected(device, device.getName()); intent.removeExtra(FeaturesActivity.EXTRA_APP); intent.removeExtra(FeaturesActivity.EXTRA_ADDRESS); } }