storage-access-framework

Saving an image after getting folder from Storage Access Framework UI

安稳与你 提交于 2019-12-23 03:42:01
问题 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

Distinguish SDCard URI from USBStorage URI returned by SAF or StorageVolume API

穿精又带淫゛_ 提交于 2019-12-23 03:05:07
问题 I am using StorageVolume API to retrieve URI for both SDCard and USBStorage by following StorageManager storageManager = (StorageManager) getSystemService(STORAGE_SERVICE); for (StorageVolume storageVolume : storageManager.getStorageVolumes()) { if (!storageVolume.isPrimary()) { Intent accessIntent = storageVolume.createAccessIntent(null); startActivityForResult(accessIntent, 11); } } In onActivityResult I am able to retrieve the URI, saving it to the SharedPreferences and taking Persisting

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

不问归期 提交于 2019-12-21 02:29:39
问题 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. 回答1: 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

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

核能气质少年 提交于 2019-12-20 04:54:09
问题 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

Get filepath from google drive in Lollipop (MediaStore.MediaColumns.DATA == null)

ぐ巨炮叔叔 提交于 2019-12-17 19:46:29
问题 When the user clicks the "send file" button in google drive and selects my app. I want to get the filepath of that file and then allow the user to upload it to a different location. I check these similar SO post for kitkat phones: Get real path from URI, Android KitKat new storage access framework Android - Convert URI to file path on lollipop However the solution to that no longer seems to work in Lollipop devices. The problem seems to be that MediaStore.MediaColumns.DATA returns null when

Unable to access file from uri

孤人 提交于 2019-12-13 07:07:45
问题 I am trying to access a file using Storage Access Framework which I have stored in locally and send it to server. but when ever I try to get file using URI I get NullPointerException . However I get the URI of file. but catches exception when converting to file by getting path. Minimum API is 17 uriString = content://com.android.providers.downloads.documents/document/349 warantyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent =

Storage Access Provider - Creation of folder in authorized directory fails

大兔子大兔子 提交于 2019-12-13 05:33:46
问题 My app lets the user create a folder with the SAF picker and then wants to create a folder in it. This is how the picker is called: static public void openPickerForFolderCreation(Activity activity,int requestCode) { Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); intent.setType("vnd.android.document/directory"); intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.addFlags(Intent.FLAG_GRANT_WRITE_URI

Error while creating new File in SD Card using DocumentFile.createFile();

◇◆丶佛笑我妖孽 提交于 2019-12-12 04:58:26
问题 I am trying to create a new File in SD Card for Android 5.0 and above. So first I am making the user grant the permission through SAF. This is how I am check if the selected Directory is SD Card or Not. public static boolean wrong_directory_selected(Uri uri, Context con) { final File uri_path=new File(FileUtil.getFullPathFromTreeUri(uri,con)); if(uri_path.getName().toLowerCase().equals(new File("SD CARD PATH").getName().toLowerCase())) { return false; } return true; } And then this is how I

Android - Storage Access Framework - Uri into local file

与世无争的帅哥 提交于 2019-12-12 04:17:22
问题 I am using Storage Access Framework(SAF) in my app. In order to scan a file(photo or document) i need send a local file path trough an API. I've managed to setup the SAF correctly, and now when a user chooses a file and i am getting a Uri as it supposed to be. As it seems the Uri is a key for the cloud and not a local file. The Uri value looks like that: content://com.android.providers.media.documents/document/image:11862 How can i convert this Uri into a local file? Should i download the

Get Persistable SD Cad write Permission using SAF

纵饮孤独 提交于 2019-12-12 03:52:34
问题 In my application, list of Image files is inflated in recyclerview. Then after application edits the metadata of Image file. My code for writing metadata:- DocumentFile fos = DocumentFile.fromFile(new File(fileIn)); ByteSource bytsInputStream = new ByteSourceFile(new File(fileIn)); byte[] byteArrayInputStream = bytsInputStream.getAll(); try { ParcelFileDescriptor pfd = context.getContentResolver(). openFileDescriptor(fos.getUri(), "w"); FileOutputStream fileOutputStream = new FileOutputStream