Mercurial > dwindows
diff android/DWindows.kt @ 2795:5c61aba17b69
Android: Change dw_file_browse() to return URIs or paths on Android.
Paths will be returned if either DW_DIRECTORY_OPEN or DW_FILE_PATH flags are
specified. Otherwise a URI may be returned. The double string method of
returning both path and URI has been removed. DW_FILE_PATH and DW_FILE_MASK
have been added, but are really only used on Android.
__DW_MOBILE__ will be defined on Mobile platforms such as iOS and Android.
__DW_DESKTOP__ will be defined on most other desktop operating systems.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 15 Jul 2022 11:50:09 +0000 |
parents | 20d39af27aa4 |
children | 0c534743b7a9 |
line wrap: on
line diff
--- a/android/DWindows.kt Fri Jul 15 08:15:11 2022 +0000 +++ b/android/DWindows.kt Fri Jul 15 11:50:09 2022 +0000 @@ -6126,7 +6126,6 @@ fun fileBrowseNew(title: String, defpath: String?, ext: String?, flags: Int): String? { var retval: String? = null - var uristr: String? = null var permission = Manifest.permission.WRITE_EXTERNAL_STORAGE var permissions: Int = -1 @@ -6161,57 +6160,61 @@ fileLock.unlock() // Save the URI string for later use - uristr = fileURI.toString() - - if (DocumentsContract.isDocumentUri(this, fileURI)) { - // ExternalStorageProvider - if (fileURI?.authority == "com.android.externalstorage.documents") { - val docId = DocumentsContract.getDocumentId(fileURI) - val split = docId.split(":").toTypedArray() - retval = Environment.getExternalStorageDirectory().toString() + "/" + split[1] - } else if (fileURI?.authority == "com.android.providers.downloads.documents") { - val id = DocumentsContract.getDocumentId(fileURI) - val contentUri = ContentUris.withAppendedId( - Uri.parse("content://downloads/public_downloads"), - java.lang.Long.valueOf(id) - ) - retval = getDataColumn(this, contentUri, null, null) - } else if (fileURI?.authority == "com.android.providers.media.documents") { - val docId = DocumentsContract.getDocumentId(fileURI) - val split = docId.split(":").toTypedArray() - val type = split[0] - var contentUri: Uri? = null - if ("image" == type) { - contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI - } else if ("video" == type) { - contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI - } else if ("audio" == type) { - contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI + retval = fileURI.toString() + + // If DW_DIRECTORY_OPEN or DW_FILE_PATH ... use the path not URI + if((flags and 65535) == 2 || ((flags shr 16) and 1) == 1) { + if (DocumentsContract.isDocumentUri(this, fileURI)) { + // ExternalStorageProvider + if (fileURI?.authority == "com.android.externalstorage.documents") { + val docId = DocumentsContract.getDocumentId(fileURI) + val split = docId.split(":").toTypedArray() + retval = Environment.getExternalStorageDirectory() + .toString() + "/" + split[1] + } else if (fileURI?.authority == "com.android.providers.downloads.documents") { + val id = DocumentsContract.getDocumentId(fileURI) + val contentUri = ContentUris.withAppendedId( + Uri.parse("content://downloads/public_downloads"), + java.lang.Long.valueOf(id) + ) + retval = getDataColumn(this, contentUri, null, null) + } else if (fileURI?.authority == "com.android.providers.media.documents") { + val docId = DocumentsContract.getDocumentId(fileURI) + val split = docId.split(":").toTypedArray() + val type = split[0] + var contentUri: Uri? = null + if ("image" == type) { + contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI + } else if ("video" == type) { + contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI + } else if ("audio" == type) { + contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI + } + val selection = "_id=?" + val selectionArgs = arrayOf<String?>( + split[1] + ) + retval = getDataColumn(this, contentUri, selection, selectionArgs) } - val selection = "_id=?" - val selectionArgs = arrayOf<String?>( - split[1] - ) - retval = getDataColumn(this, contentUri, selection, selectionArgs) + } else if (fileURI?.scheme == "content") { + retval = getDataColumn(this, fileURI, null, null) + } + // File + else if (fileURI?.scheme == "file") { + retval = fileURI?.path } - } else if (fileURI?.scheme == "content") { - retval = getDataColumn(this, fileURI, null, null) - } - // File - else if (fileURI?.scheme == "file") { - retval = fileURI?.path - } - - // If we are opening a directory DW_DIRECTORY_OPEN - if(retval != null && flags == 2) { - val split = retval.split("/") - val filename = split.last() - - if(filename != null) { - val pathlen = retval.length - val filelen = filename.length - - retval = retval.substring(0, pathlen - filelen - 1) + + // If we are opening a directory DW_DIRECTORY_OPEN + if (retval != null && (flags and 65535) == 2) { + val split = retval.split("/") + val filename = split.last() + + if (filename != null) { + val pathlen = retval.length + val filelen = filename.length + + retval = retval.substring(0, pathlen - filelen - 1) + } } } } else { @@ -6220,9 +6223,6 @@ retval = fileBrowse(title, defpath, ext, flags) } } - if(retval != null && uristr != null) { - return retval + "\n\n" + uristr - } return retval }