title: unable to write File to usb storage
body: <p>I am trying to create file dir to connected usb storage I have written following code to create dir :</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      private static final String ACTION_USB_PERMISSION = "com.example.usbtest.USB_PERMISSION";
      UsbManager mUsbManager;
      UsbDevice device;
  
      String s = null;
      TextView tvusb;
  
      private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
              String action = intent.getAction();
              if (ACTION_USB_PERMISSION.equals(action)) {
                  synchronized (this) {
                      UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
                      if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                          if (device != null) {
                              Toast.makeText(getApplicationContext(), "permission allowed" + device, Toast.LENGTH_LONG).show();
                              //call method to set up device communication
                          }
                      } else {
                          Toast.makeText(getApplicationContext(), "permission not allowed" + device, Toast.LENGTH_LONG).show();
                          Log.d("usb", "permission denied for device " + device);
                      }
                  }
              }
          }
      };
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
          tvusb = (TextView) findViewById(R.id.tvusb);
  
          mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
  
          HashMap&lt;String, UsbDevice&gt; deviceList = mUsbManager.getDeviceList();
          Iterator&lt;UsbDevice&gt; deviceIterator = deviceList.values().iterator();
          while (deviceIterator.hasNext()) {
              device = deviceIterator.next();
  
              s = device.getDeviceName();
  
              int pid = device.getProductId();
              int vid = device.getVendorId();
              device = deviceList.get(s);
  
              tvusb.setText(s + "\n" + Integer.toString(pid) + "\n" + Integer.toString(vid));
          }
  
  
          PendingIntent mPermissionIntent;
  
  
          mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
  
          IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
  
  
          registerReceiver(mUsbReceiver, filter);
  
          mUsbManager.requestPermission(device, mPermissionIntent);
  
  
          File fileContact = new File(s, "Contact");
          if (!fileContact.exists()) {
              fileContact.mkdirs();
          }
  
          if (!confirmDir(fileContact)) {
  
              Toast.makeText(getApplicationContext(), "Unable to create " + String.valueOf(fileContact), Toast.LENGTH_LONG).show();
  
          }
  
      }
  
      private static boolean confirmDir(File dir) {
          if (dir.isDirectory()) return true;  // already exists
          if (dir.exists()) return false;      // already exists, but is not a directory
          return dir.mkdirs();                 // create it
      }
  
  }
  </code></pre>
  
  <p>manifest:</p>
  
  <pre><code>&lt;manifest
  
      xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
      &lt;uses-permission android:name="android.permission.usb"&gt;&lt;/uses-permission&gt;
  
      &lt;uses-feature android:name="android.hardware.usb.host"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_SETTINGS"/&gt;
  
      &lt;uses-feature android:name="android.hardware.usb.accessory"/&gt;
  
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.READ_INTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;uses-library android:name="com.android.future.usb.accessory"/&gt;
  
  
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name"
              android:theme="@style/AppTheme.NoActionBar"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN"/&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER"/&gt;
              &lt;/intent-filter&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"/&gt;
              &lt;/intent-filter&gt;
  
              &lt;meta-data
                  android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
                  android:resource="@xml/accessory_filter"/&gt;
  
          &lt;/activity&gt;
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>I have also written - <code>File fileContact = new File("/storage/emulated/0", "Contact");</code></p>
  
  <p>But I am unable to create dir to usb storage. </p>
  
  <p>How can I create dir to usb storage?</p>