Skip to content

Commit 86a93a7

Browse files
Merge pull request #200 from NativeScript/tgpetrov/android-pick-local
chore: allow only local files for picking
2 parents c5c078e + c04d89d commit 86a93a7

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

demo-angular/package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"tns-core-modules": "^4.0.0"
2727
},
2828
"devDependencies": {
29-
"@angular/compiler-cli": "~6.1.0-beta.1",
3029
"babel-traverse": "6.24.1",
3130
"babel-types": "6.24.1",
3231
"babylon": "6.16.1",
@@ -42,8 +41,7 @@
4241
"tns-platform-declarations": "^3.0.0",
4342
"tslint": "~5.4.3",
4443
"typescript": "~2.7.2",
45-
"zone.js": "^0.8.4",
46-
"@ngtools/webpack": "6.1.0-rc.0"
44+
"zone.js": "^0.8.4"
4745
},
4846
"scripts": {
4947
"build.plugin": "cd ../src && npm run build",

src/imagepicker.android.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class UriHelper {
2626
// DownloadsProvider
2727
else if (UriHelper.isDownloadsDocument(uri)) {
2828
id = DocumentsContract.getDocumentId(uri);
29+
// Since Oreo the downloads id may be a raw string,
30+
// containing the file path:
31+
if (id.indexOf("raw:") !== -1) {
32+
return id.substring(4, id.length);
33+
}
2934
contentUri = android.content.ContentUris.withAppendedId(
3035
android.net.Uri.parse("content://downloads/public_downloads"), long(id));
3136

@@ -196,8 +201,8 @@ export class ImagePicker {
196201
intent.putExtra("android.intent.extra.ALLOW_MULTIPLE", true);
197202
}
198203

199-
intent.setAction(Intent.ACTION_GET_CONTENT);
200-
204+
intent.putExtra(android.content.Intent.EXTRA_LOCAL_ONLY, true);
205+
intent.setAction("android.intent.action.OPEN_DOCUMENT");
201206
let chooser = Intent.createChooser(intent, "Select Picture");
202207
application.android.foregroundActivity.startActivityForResult(intent, RESULT_CODE_PICKER_IMAGES);
203208
});

0 commit comments

Comments
 (0)