documentfile

Android - get DocumentFile with write access for any file path on sd card (having allready gained sd card permission)

房东的猫 提交于 2019-12-04 23:08:42
问题 In my app I gain sd card write permission using the following intent. If the user selects the sd card folder from the system file explorer then I have sd card write access. Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); intent.putExtra("android.content.extra.SHOW_ADVANCED", true); startActivityForResult(intent, 42); After that I am able to modify files in th sd card using the DocumentFile class. But I'm having problem getting a DocumentFile for a random file path. Document

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

Bug when listing files with Android Storage Access framework on Lollipop

拜拜、爱过 提交于 2019-12-02 22:39:24
Background I have a few apps that make heavy use of SD card for file syncing. The broken external SD card access on Kitkat is still a big problem, but I am trying to resolve this with the new API available on Lollipop for the users which have this. I successfully request and persist permission to SD card and I can list files in the root Uri returned from the grant permission activity. See more info on how this is done here: how-to-use-the-new-sd-card-access-api-presented-for-lollipop The user can then select any folder/subfolder for sync and I persist the folder document Uri as a string in the

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 =

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 get random access to a file on SD-Card by means of API presented for Lollipop?

◇◆丶佛笑我妖孽 提交于 2019-11-28 21:41:50
My application uses Java class RandomAccessFile to read/write bytes to a file on SD card randomly by means of realization of SeekableByteChannel interface. Now I need rewrite it for Android 5.0 with new Lollipop API. I have found the only way to read: InputStream inputStream = getContentResolver().openInputStream(uri); and write: ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "w"); FileOutputStream fileOutputStream = new FileOutputStream(pfd.getFileDescriptor()); from/to a file in new API. I would like to have an ability to set channel in some random

How to get access to all SD-cards, using the new Lollipop API?

Deadly 提交于 2019-11-28 17:53:26
background Starting with Lollipop, apps can get access to real SD-cards (after it was not accessible on Kitkat, and was not officially supported yet worked on previous versions), as I've asked about here . The problem Because it has become quite rare to see a Lollipop device that supports SD-card and because the emulator doesn't really has the ability (or does it?) to emulate an SD-card support, it took me quite a while to test it. Anyway, it seems that instead of using the normal File classes to access the SD-card (once you got a permission for it), you need to use Uris for it, using

Android 5.0 DocumentFile from tree URI

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 07:44:05
Alright, I've searched and searched and no one has my exact answer, or I missed it. I'm having my users select a directory by: Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, READ_REQUEST_CODE); In my activity I want to capture the actual path, which seems to be impossible. protected void onActivityResult(int requestCode, int resultCode, Intent intent){ super.onActivityResult(requestCode, resultCode, intent); if (resultCode == RESULT_OK) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M){ //Marshmallow } else if (android.os

How to get random access to a file on SD-Card by means of API presented for Lollipop?

折月煮酒 提交于 2019-11-27 14:01:56
问题 My application uses Java class RandomAccessFile to read/write bytes to a file on SD card randomly by means of realization of SeekableByteChannel interface. Now I need rewrite it for Android 5.0 with new Lollipop API. I have found the only way to read: InputStream inputStream = getContentResolver().openInputStream(uri); and write: ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "w"); FileOutputStream fileOutputStream = new FileOutputStream(pfd

Android SD Card Write Permission using SAF (Storage Access Framework)

微笑、不失礼 提交于 2019-11-27 00:51:45
After a lot of findings about how to write(and rename) a file in SD Card (android 5 and above), I think the new SAF provided by android will be required to take permission from user to write SD card file. I have seen in this File Manger Application ES File Explorer that initially it takes read and write permission the following way as shown in pictures. After selecting sd card, the write permission is granted. So in the same way I tried to use SAF, but failed in renaming a file. My code: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);