簡體   English   中英

如何在地址中只顯示藍牙名稱

[英]how to display only bluetooth name in address

嗨,在下面的代碼中顯示藍牙設備名稱。 假設設備默認沒有名稱,它顯示藍牙地址。

現在我的疑問是想每次只顯示藍牙名稱。 有時顯示藍牙名稱,有時顯示藍牙地址。

任何人都可以幫我想每次都顯示藍牙名稱。

@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());
                }
            }
        }
    }

每個藍牙設備都沒有名稱。 但是是的地址將永遠存在。 因此,請首先確保您的藍牙設備是否有名稱,否則您可以顯示一些默認名稱而不是顯示地址。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM