![]() ![]() VolumePath = (String)method_getPath.invoke(volume) If (_INT = Build.VERSION_CODES.Q)įinal Class class_StorageVolume = Method method_getPath = class_StorageVolume.getDeclaredMethod("getPath") There must be a better way to get the document segmentįinal String documentId = DocumentsContract.getDocumentId(document.getUri()) įinal String documentSegment = documentId.substring(documentId.lastIndexOf(':') + 1) įor (final StorageVolume volume : volumeList) If ((volumeList = null) || volumeList.isEmpty()) static File final Context context, final DocumentFile document) In my tests the resolved path works fine with the MediaScannerConnection, but it may need adjustments to handle other requirements. Is not official so there is no guaranty it will work for all use cases, and I recommend against using it for production purposes. ![]() ![]() The next sample (a bit hacky) can help to resolve a file path in APIs 29 & 30 not tested below 29. Any workaround will be temporary and harder to maintain with each new Android version. I would recommend to work only with Uris / File Descriptors via the ContentResolver, and get away from real file paths. If performance is important then is better to use directly the MediaStore API. Underneath now delegates all the operations to the MediaStore. Note that the File API in Android 11 and all future versions is much slower with a penalty hit, because has been rewritten into a wrapper, so is no longer a File system API. Out of these locations the File API will not work, neither in Android 10. The documentation for API 30 (Andorid 11) stating that the older File API can be used, refers to the fact that such API can now be used to access/work with files located in the "shared storage" folders, so DCIM, Music, etc.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |