0

Unable to create a folder or file in USB storage android version above 5.0+ non-root device using this method

File dest = new File("storage/usbotg/usbname/foldername"); dest.mkdir();

I will successfully created a file or folder in internal storage using ndk c by below code .
FILE* fp = fopen("/sdcard/sample.txt","w+");

but unable to create usb storage via appliaction .

FILE* fp = fopen("/storage/2F5A-E677/sample.txt","w+");

Muhamed El-Banna
  • 593
  • 7
  • 21
kumar
  • 469
  • 2
  • 5
  • 10
  • Yes we already know that long time. Any questions?. – blackapps Mar 16 '20 at 12:18
  • can u give any idea to how can i solve it ? u given for Android Q . But i want to support from Android 5.0. – kumar Mar 16 '20 at 12:47
  • Android Q, what about it ? – blackapps Mar 16 '20 at 13:59
  • i got this kind of exception java.lang.UnsupportedOperationException: Unknown URI: content://media/12B1-1800/file – kumar Mar 17 '20 at 12:59
  • There is no code that could cause such an exception. – blackapps Mar 17 '20 at 16:38
  • i just tried your sample snippet code in Android 5.0 . Refer : https://stackoverflow.com/questions/60179299/writing-files-to-publicly-accessible-documents-folder-in-android-q-scoped-stor/60 – kumar Mar 18 '20 at 08:45
  • Also i mentioned write external storage permission in manifest.xml file. – kumar Mar 18 '20 at 08:48
  • You should post the used code in your post. We dont know what you are doing at all. – blackapps Mar 18 '20 at 09:21
  • String relative_path = "Documents/Myfoldername"; String collection = "content://media/12B1-1800//file"; Uri collectionUri = Uri.parse(collection); byte[] data = new String("Hello").getBytes(); ContentValues contentValues = new ContentValues(); contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, "hello.txt"); contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "text/plain"); contentValues.put(MediaStore.MediaColumns.SIZE, data.length); Uri fileUri = getContentResolver().insert(collectionUri, contentValues); – kumar Mar 18 '20 at 09:30

0 Answers0