Skip to content

Commit 408f507

Browse files
authored
fix(android): Fix picking from 'SDCARD' location (#326)
1 parent 72c4d05 commit 408f507

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/imagepicker.android.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,20 @@ class UriHelper {
2222

2323
if ("primary" === type.toLowerCase()) {
2424
return android.os.Environment.getExternalStorageDirectory() + "/" + id;
25+
} else {
26+
if (android.os.Build.VERSION.SDK_INT > 23) {
27+
(this.getContentResolver() as any).takePersistableUriPermission(
28+
uri,
29+
android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION | android.content.Intent.FLAG_GRANT_WRITE_URI_PERMISSION,
30+
);
31+
const externalMediaDirs = application.android.context.getExternalMediaDirs();
32+
if (externalMediaDirs.length > 1) {
33+
let filePath = externalMediaDirs[1].getAbsolutePath();
34+
filePath = filePath.substring(0, filePath.indexOf("Android")) + id;
35+
return filePath;
36+
}
37+
}
2538
}
26-
27-
// TODO handle non-primary volumes
2839
}
2940
// DownloadsProvider
3041
else if (UriHelper.isDownloadsDocument(uri)) {

0 commit comments

Comments
 (0)