Android: How to find out name of the bluetooth device connected?

后端 未结 1 850
轻奢々
轻奢々 2020-12-17 02:37

Basically im trying 2 things here, Im trying to start a toast when my bluetooth device is connected to a particular device (so need to check if that is the particular blueto

1条回答
  •  余生分开走
    2020-12-17 03:24

    Change your broadcast receiver to:

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
    
            // When discovery finds a device
            if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
                // Get the BluetoothDevice object from the Intent
                BluetoothDevice device = intent
                        .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
    
                              //you can get name by device.getName()
    
            } else if (BluetoothAdapter.ACL_DISCONNECTED
                    .equals(action)) {
    
            }
        }
     };
    

    0 讨论(0)
提交回复
热议问题