简体   繁体   中英

how to display only bluetooth name in address

Hi in the below code displaying the Bluetooth device names. suppose there is no name for the device default it was displaying the Bluetooth address.

Now my doubt is want to display only Bluetooth name for every time. Sometime Bluetooth name is displaying and sometimes Bluetooth address is displaying.

can any one please help me want to show every time Bluetooth name.

@Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final DeviceListViewHolder viewHolder = (DeviceListViewHolder) holder;
        if (mDevices != null) {
            BluetoothDevice bluetoothDevice = mDevices.get(position);
            if (bluetoothDevice != null) {
                String deviceName = bluetoothDevice.getName();
                if (!TextUtils.isEmpty(deviceName)) {
                    viewHolder.mDeviceName.setText(deviceName);
                } else {
                    viewHolder.mDeviceName.setText(bluetoothDevice.getAddress());
                }
            }
        }
    }

Every Bluetooth device will not have a name. But yes address will always be there. So, make sure first whether your Bluetooth device is having a name if not then you can display some default name instead displaying address.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM