storage-access-framework

Attempt to write Serializable Object with SAF gives as result an empty file

╄→гoц情女王★ 提交于 2020-06-28 05:50:17
问题 I want to use SAF to write Object files To write a text files If I try: DocumentFile txtfile=df.createFile("text", "myfile.txt"); Uri source = txtfile.getUri(); resolver = getContentResolver(); OutputStream os = resolver.openOutputStream(source); PrintWriter out = new PrintWriter(new OutputStreamWriter(os)); out.print(somestring); out.flush(); out.close(); the file is correctly created and written. But if I try in a similar way to write a Serializable object rather than a string with this

Storage Access Framework - Cannot create file in cloud folder selected with ACTION_OPEN_DOCUMENT_TREE (NextCloud)

不羁岁月 提交于 2020-01-25 08:07:49
问题 I am experimenting with Storage Access Framework. I am using NextCloud platform. This platform supports the ACTION_OPEN_DOCUMENT_TREE intent, that the GDrive app itself does not support yet. My app lets the user select a cloud folder on the provider I decided to connect to NextCloud service. static public void openPickerForFolderSelection(Activity activity, int requestCode) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI

Storage Access Framework - Events produced by file operations in folder

痞子三分冷 提交于 2020-01-25 06:53:27
问题 Is it possible to receive file-operations events happening inside a folder under Storage Access Framework into an Android app? I mean, a folder that was selected by the user, and thus authorized. The app has the corresponding uri in a suitable form. When a file is modified, created or removed inside that folder an event should reach the Android app back, even if this time no operations were performed by the app itself or from the device in use. Is this possible? 来源: https://stackoverflow.com

Creating a writeable DocumentFile from URI

廉价感情. 提交于 2020-01-24 19:44:05
问题 I'm trying to adapt a File -based document system to something using DocumentFile in order to allow external storage read/write access on API >= 29. I get the user to select the SD card root using Intent.ACTION_OPEN_DOCUMENT_TREE , and I get back a Uri as expected, which I can then handle using: getContentResolver().takePersistableUriPermission(resultData.getData(), Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); I can browse successfully through the external

How to get child TreeDocumentFile from child Uri?

橙三吉。 提交于 2020-01-24 19:32:47
问题 [Rewrite, based on comments] Simplified example: rootUri is obtained by ACTION_OPEN_DOCUMENT_TREE . Then I create a folder (or more nested folders): val rootTree = DocumentFile.fromTreeUri(context, rootUri) // rootTree.name == "treeRoot" val childTree = rootTree.createDirectory("ChildDir1") // childTree.name == "ChildDir1" val childUriStr = childTree.uri.toString() I store childUriStr into local database so I can later recreate childTree . childUriStr contains all elements needed: authority ,

How to get child TreeDocumentFile from child Uri?

这一生的挚爱 提交于 2020-01-24 19:32:10
问题 [Rewrite, based on comments] Simplified example: rootUri is obtained by ACTION_OPEN_DOCUMENT_TREE . Then I create a folder (or more nested folders): val rootTree = DocumentFile.fromTreeUri(context, rootUri) // rootTree.name == "treeRoot" val childTree = rootTree.createDirectory("ChildDir1") // childTree.name == "ChildDir1" val childUriStr = childTree.uri.toString() I store childUriStr into local database so I can later recreate childTree . childUriStr contains all elements needed: authority ,

SAF - Attempting to create again an existing folder/file yields a new folder/file

本小妞迷上赌 提交于 2019-12-25 01:15:21
问题 Is SAF intended to replace File handling in external directories, in a certain future? I hope it is not so in the end, but I am testing SAF itself in advance. It would be useful for other reasons too. Let's say I am using this method: static public DocumentFile createFolderInFolder(Activity activity,String parentFolderUriString,String folderName) { DocumentFile result=null; ContentResolver contentResolver; contentResolver = activity.getContentResolver(); Uri parentFolderUri=null; Uri

Storage Access Framework - How to append to a created file using its URI?

笑着哭i 提交于 2019-12-24 06:17:10
问题 Using the answer in this post, I was able to use OPEN_CREATE_DOCUMENT as a folder picker in order for GDrive to appear in the list. The code in that answer creates an empty file. Now, I'm trying to append/write to that file. I tried using DocumentFile and openFileDescriptor. Both of them are failing. The latter with a permission denial exception saying that I need to add MANAGE_DOCUMENTS or use uripermission(). We cant use MANAGE_DOCUMENTS in the manifest since its a system permission and I

Android Q: Get image from gallery and process it

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 03:53:19
问题 I know it seems like a very basic question, but it's specifically for Android Q. I just want to get an image from Gallery and compress it and send to the server. But because of the Android Q's Scoped Storage, it's harder than I thought. I'll first explain what I did with code: First I send out the intent to pick the image. fun openGallery(fragment: Fragment){ val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI) intent.type = "*/*" val mimeTypes = arrayOf(

Saving an image after getting folder from Storage Access Framework UI

三世轮回 提交于 2019-12-23 03:42:07
问题 I set a preference for users to select save folder for my app using Storage Access Framework. After getting uri onActivityResult I save it to SharedPreferences as String and save image when it's to be saved. I'm using this method to save image successfully. public void saveImageWithDocumentFile(String uriString, String mimeType, String name) { isImageSaved = false; try { Uri uri = Uri.parse(uriString); DocumentFile pickedDir = DocumentFile.fromTreeUri(this, uri); DocumentFile file = pickedDir