Shashank Degloorkar
Shashank Degloorkar

Reputation: 3221

Lollipop SDCard Document write

I have a third party library which accepts a File object and modifies the same. Now after getting the permission to SD card using

 Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);

And selecting SD card root.

then user browses through the files which he wants to modify. Now this file's path/ file object I need to pass to the third party library class.

 DocumentFile documentFile = DocumentFile.fromFile(file);
 String documentURI = documentFile.getUri().toString();
 MP3File mp3File = null;

 documentFile = DocumentFile.fromFile(file);
 mp3File = new MP3File(file.getAbsolutePath());

Here MP3File class accepts file path. but this class does not have any Document constructor.

Can i convert document to a writable file which i can replace with the original file? Or is there any simpler solution?

Upvotes: 0

Views: 131

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006944

Now after getting the permission to SD card using... And selecting SD card root.

There is no requirement for the user to choose any particular document. The document might be on removable storage, or external storage, or Google Drive, or Dropbox, or a file server, or anywhere else the user can access.

Now this file's path/ file object I need to pass to the third party library class.

There is no "path/file object" for that document.

Here MP3File class accepts file path

Either:

  • Find a better library, one that accepts an InputStream and/or OutputStream, so you can work with the document where it resides, or

  • Use Java I/O to copy the document's contents to a local file that you control, then pass that file to the library

Upvotes: 2

Related Questions