简体   繁体   中英

How to create new file in secondary SD card of Android Lollipop device?

In my app I use MediaMuxer to create a video file. Constructor of MediaMuxer requires absolute path of output file. Everything is ok with primary storage, but for secondary storage app doesn't work. As I check, in Lollipop user has to pick output directory in external storage, using new Intent ACTION_OPEN_DOCUMENT_TREE ( How to use the new SD card access API presented for Android 5.0 (Lollipop)? ) But on result of this Intent we get DocumentFile. I don't know how to create new video file with MediaMuxer and this DocumentFile. Can someone help me?

There is a method createFile(String mimeType, String displayName) - just call it on the DocumentFile directory instance:

DocumentFile newFile = documentFileDir.createFile("application/octet-stream", fileName);
OutputStream os = getContentResolver().openOutputStream(newFile.getUri());
... // write your data

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