Toast.makeText(MainActivity.this, "writing error",Toast.LENGTH_LONG).show() įrom android 4.4, you can use Storage Access Framework to access to removable media (see ).įor example, I tried with success to copy a pdf file from local memory to removable memory connected by OTG adapter. File file = new File("/storage/extSdCard","test.txt") įileOutputStream f = new FileOutputStream(file) Here's my code: File file = new File(path.getAbsolutePath(), "test.txt") Moreover, I can write anything to my USB using Root Browser (use it without root) and Simple Browser thus I believe that there's a way to do that. In Android Manifest so I wondered why my code didn't work. The first one returns internal storage path and the second one returns an error with "permission denied". I've tried to use Environment.getExternalStorageDirectory() to get the path or use the path (mentioned above) directly but neither of them succeed.
The complete path of my USB is /storage/UsbDriveA. My phone supports micro-USB-OTG and I can mount my USB as rwxrwx-x without rooting. I am using Samsung galaxy Note II running stock TouchWiz 4.4.2. My case is quite similar but I think that writing files to external USB is a totally different case. Others who wanted to write files on external SD card didn't success at all. I've been searching for many topics about android file writing, yet most of them wanted to write files to android internal storage.