MCPcopy Index your code
hub / github.com/NativeScript/nativescript-imagepicker / getDataColumn

Method getDataColumn

src/imagepicker.android.ts:68–119  ·  view source on GitHub ↗
(uri: android.net.Uri, selection, selectionArgs, isDownload: boolean)

Source from the content-addressed store, hash-verified

66 }
67
68 private static getDataColumn(uri: android.net.Uri, selection, selectionArgs, isDownload: boolean) {
69 let cursor = null;
70 let filePath;
71 if (isDownload) {
72 let columns = ["_display_name"];
73 try {
74 cursor = this.getContentResolver().query(uri, columns, selection, selectionArgs, null);
75 if (cursor != null && cursor.moveToFirst()) {
76 let column_index = cursor.getColumnIndexOrThrow(columns[0]);
77 filePath = cursor.getString(column_index);
78 if (filePath) {
79 const dl = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DOWNLOADS);
80 filePath = `${dl}/${filePath}`;
81 return filePath;
82 }
83 }
84 }
85 catch (e) {
86 console.log(e);
87 }
88 finally {
89 if (cursor) {
90 cursor.close();
91 }
92 }
93 }
94 else {
95 let columns = [android.provider.MediaStore.MediaColumns.DATA];
96 let filePath;
97
98 try {
99 cursor = this.getContentResolver().query(uri, columns, selection, selectionArgs, null);
100 if (cursor != null && cursor.moveToFirst()) {
101 let column_index = cursor.getColumnIndexOrThrow(columns[0]);
102 filePath = cursor.getString(column_index);
103 if (filePath) {
104 return filePath;
105 }
106 }
107 }
108 catch (e) {
109 console.log(e);
110 }
111 finally {
112 if (cursor) {
113 cursor.close();
114 }
115 }
116 }
117 return undefined;
118
119 }
120
121 private static isExternalStorageDocument(uri: android.net.Uri) {
122 return "com.android.externalstorage.documents" === uri.getAuthority();

Callers 1

_calculateFileUriMethod · 0.80

Calls 1

getContentResolverMethod · 0.95

Tested by

no test coverage detected