I didn't try this with wired devices but I did this for Bluetooth devices like this-
BluetoothManager btManager = (BluetoothManager)
getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
bluetoothAdapter.cancelDiscovery();
bluetoothAdapter.getProfileProxy(this, listener, BluetoothProfile.HEADSET);
public final BluetoothProfile.ServiceListener listener = new BluetoothProfile.ServiceListener() {
@Override
public void onServiceConnected(int i, final BluetoothProfile bluetoothProfile) {
final TextView device = (TextView) findViewById(R.id.device);
List<BluetoothDevice> b = bluetoothProfile.getConnectedDevices();
StringBuilder stringBuilder = new StringBuilder();
for(BluetoothDevice getConnectedDevice : b){
stringBuilder.append(getConnectedDevice.getName());
}
device.setText(stringBuilder);
}
@Override
public void onServiceDisconnected(int i) {
final TextView device = (TextView) findViewById(R.id.device);
device.setText(String.valueOf(i));
}
};
You can try this for Bluetooth devices, I hope it helps.