storage-access-framework

Android - How to use new Storage Access Framework to copy files to external sd card

拟墨画扇 提交于 2019-12-06 04:06:07
问题 I'm implementing a file browser feature in my app. I know how to gain persistent permission for the external sd card using the ACTION_OPEN_DOCUMENT_TREE intent and how to create folders and delete files/folders using the DocumentFile class. I can't however find a way to copy/move a file to an external sd card folder. Can you point me to the right direction ? 回答1: I have figured it out using lots of examples on SO. My solution for music files: private String copyFile(String inputPath, String

Android - How to use new Storage Access Framework to copy files to external sd card

梦想的初衷 提交于 2019-12-04 12:35:18
I'm implementing a file browser feature in my app. I know how to gain persistent permission for the external sd card using the ACTION_OPEN_DOCUMENT_TREE intent and how to create folders and delete files/folders using the DocumentFile class. I can't however find a way to copy/move a file to an external sd card folder. Can you point me to the right direction ? I have figured it out using lots of examples on SO. My solution for music files: private String copyFile(String inputPath, String inputFile, Uri treeUri) { InputStream in = null; OutputStream out = null; String error = null; DocumentFile

SAF - Invalid URI error from DocumentsContract.createDocument method (FileOutputStream copy)

∥☆過路亽.° 提交于 2019-12-04 05:50:24
问题 My app is migrating to SAF or, at least some experimentation is going about. Now it has to copy a file from private app folder to a SAF folder that was authorized. The used method is: static boolean copyFileToTargetFolderWithNewName(Activity activity, String filePath,String targetFolderUri,String newName) { File file = new File(filePath); FileInputStream fis=null; Uri docUri=null; try { fis=new FileInputStream(file); } catch (FileNotFoundException e) { return false; } deleteIfExisting

Extra to enable the Show/Hide SD Card with Storage Access Framework (SAF)

旧时模样 提交于 2019-12-03 07:21:43
I am using the Storage Access Framework (SAF) : Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); startActivityForResult(intent, 0); I would like to know if there is an extra to enable the Show SD Card option, that user can see in the overflow menu. Add intent.putExtra("android.content.extra.SHOW_ADVANCED", true); But be aware that this is not part of the official API. So there is a good chance this will stop working in future Android versions. The relevant Framework code can be found here: http://grepcode.com/file

Issues traversing through directory hierarchy with Android Storage Access Framework / DocumentProvider using MTP

流过昼夜 提交于 2019-12-02 05:29:54
UPDATE: My initial question may be misleading so I want to rephrase it: I want to traverse through the hierarchy tree from an MTP connected device through Android's Storage Access Framework. I can't seem to achieve this because I get a SecurityException stating that a subnode is not a descendant of its parent node. Is there a way to workaround this issue? Or is this a known issue? Thanks. I'm writing an Android application that attempts to traverse and access documents through the hierarchy tree using Android's Storage Access Framework (SAF) via the MtpDocumentsProvider . I am more or less

ContentResolver doesn't contain just created image in an immediate query after creation of file

╄→尐↘猪︶ㄣ 提交于 2019-11-30 16:30:39
I'm using this code to copy an image using documentFile.createFile() private void newcopyFile(File fileInput, String outputParentPath, String mimeType, String newFileName) { DocumentFile documentFileGoal = DocumentFile.fromTreeUri(this, treeUri); String[] parts = outputParentPath.split("\\/"); for (int i = 3; i < parts.length; i++) { if (documentFileGoal != null) { documentFileGoal = documentFileGoal.findFile(parts[i]); } } if (documentFileGoal == null) { Toast.makeText(MainActivity.this, "Directory not found", Toast.LENGTH_SHORT).show(); return; } DocumentFile documentFileNewFile =

How to get free and total size of each StorageVolume?

假如想象 提交于 2019-11-30 11:27:23
Background Google (sadly) plans to ruin storage permission so that apps won't be able to access the file system using the standard File API (and file-paths). Many are against it as it changes the way apps can access the storage and in many ways it's a restricted and limited API. As a result, we will need to use SAF (storage access framework) entirely on some future Android version (on Android Q we can, at least temporarily, use a flag to use the normal storage permission), if we wish to deal with various storage volumes and reach all files there. So, for example, suppose you want to make a

No activity found to handle Intent - android.intent.action.OPEN_DOCUMENT

孤者浪人 提交于 2019-11-30 07:07:51
问题 I am trying my hand on Storage Access Framework of android 4.4 I have developed a dummy app which fires an intent on start of the activity. Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(intent, READ_REQUEST_CODE); Also I have developed another dummy app which serves as the file-provider. <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example

ContentResolver doesn't contain just created image in an immediate query after creation of file

删除回忆录丶 提交于 2019-11-29 23:54:40
问题 I'm using this code to copy an image using documentFile.createFile() private void newcopyFile(File fileInput, String outputParentPath, String mimeType, String newFileName) { DocumentFile documentFileGoal = DocumentFile.fromTreeUri(this, treeUri); String[] parts = outputParentPath.split("\\/"); for (int i = 3; i < parts.length; i++) { if (documentFileGoal != null) { documentFileGoal = documentFileGoal.findFile(parts[i]); } } if (documentFileGoal == null) { Toast.makeText(MainActivity.this,

How to check which StorageVolume we have access to, and which we don't?

给你一囗甜甜゛ 提交于 2019-11-29 13:08:02
问题 Background Google (sadly) plans to ruin storage permission so that apps won't be able to access the file system using the standard File API (and file-paths). Many are against it as it changes the way apps can access the storage and in many ways it's a restricted and limited API. As a result, we will need to use SAF (storage access framework) entirely on some future Android version (on Android Q we can, at least temporarily, use a flag to use the normal storage permission), if we wish to deal