@@ -25,7 +25,7 @@ class UriHelper {
25
25
}
26
26
// DownloadsProvider
27
27
else if ( UriHelper . isDownloadsDocument ( uri ) ) {
28
- return UriHelper . getDataColumn ( uri , null , null ) ;
28
+ return UriHelper . getDataColumn ( uri , null , null , true ) ;
29
29
}
30
30
// MediaProvider
31
31
else if ( UriHelper . isMediaDocument ( uri ) ) {
@@ -45,7 +45,7 @@ class UriHelper {
45
45
let selection = "_id=?" ;
46
46
let selectionArgs = [ id ] ;
47
47
48
- return UriHelper . getDataColumn ( contentUri , selection , selectionArgs ) ;
48
+ return UriHelper . getDataColumn ( contentUri , selection , selectionArgs , false ) ;
49
49
}
50
50
}
51
51
else {
@@ -62,33 +62,57 @@ class UriHelper {
62
62
return undefined ;
63
63
}
64
64
65
- private static getDataColumn ( uri : android . net . Uri , selection , selectionArgs ) {
65
+ private static getDataColumn ( uri : android . net . Uri , selection , selectionArgs , isDownload : boolean ) {
66
66
let cursor = null ;
67
67
let filePath ;
68
- let columns = [ "_display_name" ] ;
69
-
70
- try {
71
- cursor = this . getContentResolver ( ) . query ( uri , columns , selection , selectionArgs , null ) ;
72
- if ( cursor != null && cursor . moveToFirst ( ) ) {
73
- let column_index = cursor . getColumnIndexOrThrow ( columns [ 0 ] ) ;
74
- filePath = cursor . getString ( column_index ) ;
75
- if ( filePath ) {
76
- const dl = android . os . Environment . getExternalStoragePublicDirectory ( android . os . Environment . DIRECTORY_DOWNLOADS ) ;
77
- filePath = `${ dl } /${ filePath } ` ;
78
- return filePath ;
68
+ if ( isDownload ) {
69
+ let columns = [ "_display_name" ] ;
70
+ try {
71
+ cursor = this . getContentResolver ( ) . query ( uri , columns , selection , selectionArgs , null ) ;
72
+ if ( cursor != null && cursor . moveToFirst ( ) ) {
73
+ let column_index = cursor . getColumnIndexOrThrow ( columns [ 0 ] ) ;
74
+ filePath = cursor . getString ( column_index ) ;
75
+ if ( filePath ) {
76
+ const dl = android . os . Environment . getExternalStoragePublicDirectory ( android . os . Environment . DIRECTORY_DOWNLOADS ) ;
77
+ filePath = `${ dl } /${ filePath } ` ;
78
+ return filePath ;
79
+ }
80
+ }
81
+ }
82
+ catch ( e ) {
83
+ console . log ( e ) ;
84
+ }
85
+ finally {
86
+ if ( cursor ) {
87
+ cursor . close ( ) ;
79
88
}
80
89
}
81
90
}
82
- catch ( e ) {
83
- console . log ( e ) ;
84
- }
85
- finally {
86
- if ( cursor ) {
87
- cursor . close ( ) ;
91
+ else {
92
+ let columns = [ android . provider . MediaStore . MediaColumns . DATA ] ;
93
+ let filePath ;
94
+
95
+ try {
96
+ cursor = this . getContentResolver ( ) . query ( uri , columns , selection , selectionArgs , null ) ;
97
+ if ( cursor != null && cursor . moveToFirst ( ) ) {
98
+ let column_index = cursor . getColumnIndexOrThrow ( columns [ 0 ] ) ;
99
+ filePath = cursor . getString ( column_index ) ;
100
+ if ( filePath ) {
101
+ return filePath ;
102
+ }
103
+ }
104
+ }
105
+ catch ( e ) {
106
+ console . log ( e ) ;
107
+ }
108
+ finally {
109
+ if ( cursor ) {
110
+ cursor . close ( ) ;
111
+ }
88
112
}
89
113
}
90
-
91
114
return undefined ;
115
+
92
116
}
93
117
94
118
private static isExternalStorageDocument ( uri : android . net . Uri ) {
0 commit comments