title: How do i get the list of connected usb devices in android programmatically ? The following code didn't work
body: <pre><code>public class HardwareActivity extends AppCompatActivity implements View.OnClickListener {
      private static final String ACTION_USB_PERMISSION = "com.android.missilelauncher.USB_PERMISSION";
      private PendingIntent PermissionIntent;
      private Button button;
      private ImageView back;
      private TextView textInfo;
      private UsbDevice usbDevice;
      private UsbManager usbManager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          String action = getIntent().getAction();
          setContentView(R.layout.activity_hardware);
          button = (Button) findViewById(R.id.check);
          back = (ImageView) findViewById(R.id.back);
          textInfo = (TextView) findViewById(R.id.usb_info);
          back.setOnClickListener(this);
          button.setOnClickListener(this);
      }
  
      @Override
      protected void onNewIntent(Intent intent) {
          super.onNewIntent(intent);
          if (intent.getAction().equals(UsbManager.ACTION_USB_ACCESSORY_ATTACHED) || intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
              Log.d("USB DEVICE ", " device attached");
          } else if (intent.getAction().equals(UsbManager.ACTION_USB_ACCESSORY_DETACHED) || intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
              Log.d("USB DEVICE ", " device detached");
          }
      }
  
      private void checkInfo() {
          usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
          PermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(
                  ACTION_USB_PERMISSION), 0);
          HashMap&lt;String, UsbDevice&gt; deviceList = usbManager.getDeviceList();
          Iterator&lt;UsbDevice&gt; deviceIterator = deviceList.values().iterator();
          String deviceString = "";
          while (deviceIterator.hasNext()) {
              usbDevice = deviceIterator.next();
              deviceString += "\n" + "DeviceID: " + usbDevice.getDeviceId() + "\n" +
                      "DeviceName: " + usbDevice.getDeviceName() + "\n" +
                      "DeviceClass: " + usbDevice.getDeviceClass() + " - " +
                      "VendorID: " + usbDevice.getVendorId() + "\n" +
                      "ProductID: " + usbDevice.getProductId() + "\n" ;
          }
          Log.d("USB Info", "USB " + deviceString);
          textInfo.setText(deviceString);
      }
  </code></pre>