简体   繁体   中英

How to edit already present file in SD CARD using SAF(storage access framework)?

I have a doubt I read these tutorials just to get the clear understanding of the SAF introduced in kitkat in higher version of android How to use the new SD card access API presented for Android 5.0 (Lollipop)?

How to persist permission in android API 19 (KitKat)?

Android API below 19 equivalent for ContentResolver takePersistableUriPermission

Android Gallery on KitKat returns different Uri for Intent.ACTION_GET_CONTENT

Now i have a question when the intent is fired and i get select the sd card to get the uritree from the intent which i am getting but is the root tree I will have to iterate through the uri to get the specific file uri. Now the question is I have mp3 files in my phone and I want to edit that specific file which is selected so how can i get that selected files uri from the tree and edit it?I tried editing directly using file but it makes my mp3 file disappear and i dont want to fire SAF intent again n again so how to check is user has given permission to sd card or not? PS I am using jaudio tagger for editing the tags of mp3 files. THANK YOU!! I have got answers of almost everything in this question Now the issue if I am using jaudio tagger library for tagging mp3 files which takes File as a objects but android 4.4 and above wont let u modify File objects so I just want to knw the alternative how can i edit File objects in 4.4 above?

This is how I did it, first copy the file from the sdcard to the phone memory and then do the desired changes and cut and paste the file again at its original place. Example is here where I am editing the tag of mp3 file which is in the sdcard:-

https://github.com/reyanshmishra/Rey-MusicPlayer/tree/master/app/src/main/java/com/boom/music/player/TagEditor

The library you refer to is called JaudioTagger , and it does not and most probably will never accept DocumentFile . The Storage Access Framework is Google's invention and far from any standard. And JaudioTagger is written for portability.

However, I finally managed to get JaudioTagger mostly running with SAF, but had to substantially modify it, even to rewrite some functions. Basically I replaced all File and RandomAccessFile with my own classes, and additionally the handling of temporary files and renaming must be rewritten (eg the scheme: copy original file, change copy, remove original file, rename copy to original name).

In fact it might be easier to use the native TagLib instead, because that already accepts a special C++ class as input. All I did was to create such C++ class whose basis is a file descriptor derived from ParcelFileDescriptor derived from Uri derived from DocumentFile.

Finally one might come to the conclusion that the Storage Access Framework is somewhat suboptimal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM