title: How to detect USB device in Android tablet which acts as USB Host?
body: <p>I have tried developing a sample app with the help of the code from <a href="http://developer.android.com/guide/topics/connectivity/usb/host.html" rel="nofollow">Developers.android.com</a>.</p>
  
  <p>My code looks like this</p>
  
  <pre><code>  public class MainActivity extends Activity {
  
     UsbManager manager;
     HashMap&lt;String, UsbDevice&gt; deviceList;
     Button scanButton;
     UsbDevice device;
  
     @Override
      public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      scanButton = (Button)this.findViewById(R.id.button1);
      scanButton.setOnClickListener(new OnClickListener ()
      {
         public void onClick(View v) 
         {
           checkForDevices ();
         }
      });
   }
  
   @Override
    public void onResume () 
    {
      super.onResume();
      checkForDevices ();
    }
  
   @Override
    public boolean onCreateOptionsMenu(Menu menu) 
    {
      getMenuInflater().inflate(R.menu.activity_main, menu);
      return true;
    }
  
    protected void checkForDevices ()
    {
      manager = (UsbManager) getSystemService(Context.USB_SERVICE);
  
      deviceList = manager.getDeviceList();
      device = deviceList.get("deviceName");
      //Collection&lt;UsbDevice&gt; devices = deviceList.values();
  
     if (device != null)
        Toast.makeText(this, "Device Found", Toast.LENGTH_LONG).show();
     else
        Toast.makeText(this, "Device NOT Found", Toast.LENGTH_LONG).show();
    }
   }
  </code></pre>
  
  <p>When I run this code with a USB device connected, I always get the Toast as "Device NOT Found".</p>
  
  <p>I want my app to detect the USB device and Read input and Write Output in USB Host Mode.</p>
  
  <p>Is there any way to detect an USB device in our App?</p>