@@ -25,16 +25,7 @@ class UriHelper {
25
25
}
26
26
// DownloadsProvider
27
27
else if ( UriHelper . isDownloadsDocument ( uri ) ) {
28
- 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
- }
34
- contentUri = android . content . ContentUris . withAppendedId (
35
- android . net . Uri . parse ( "content://downloads/public_downloads" ) , long ( id ) ) ;
36
-
37
- return UriHelper . getDataColumn ( contentUri , null , null ) ;
28
+ return UriHelper . getDataColumn ( uri , null , null , true ) ;
38
29
}
39
30
// MediaProvider
40
31
else if ( UriHelper . isMediaDocument ( uri ) ) {
@@ -54,13 +45,13 @@ class UriHelper {
54
45
let selection = "_id=?" ;
55
46
let selectionArgs = [ id ] ;
56
47
57
- return UriHelper . getDataColumn ( contentUri , selection , selectionArgs ) ;
48
+ return UriHelper . getDataColumn ( contentUri , selection , selectionArgs , false ) ;
58
49
}
59
50
}
60
51
else {
61
52
// MediaStore (and general)
62
53
if ( "content" === uri . getScheme ( ) ) {
63
- return UriHelper . getDataColumn ( uri , null , null ) ;
54
+ return UriHelper . getDataColumn ( uri , null , null , false ) ;
64
55
}
65
56
// FILE
66
57
else if ( "file" === uri . getScheme ( ) ) {
@@ -71,31 +62,57 @@ class UriHelper {
71
62
return undefined ;
72
63
}
73
64
74
- private static getDataColumn ( uri : android . net . Uri , selection , selectionArgs ) {
65
+ private static getDataColumn ( uri : android . net . Uri , selection , selectionArgs , isDownload : boolean ) {
75
66
let cursor = null ;
76
- let columns = [ android . provider . MediaStore . MediaColumns . DATA ] ;
77
67
let filePath ;
78
-
79
- try {
80
- cursor = this . getContentResolver ( ) . query ( uri , columns , selection , selectionArgs , null ) ;
81
- if ( cursor != null && cursor . moveToFirst ( ) ) {
82
- let column_index = cursor . getColumnIndexOrThrow ( columns [ 0 ] ) ;
83
- filePath = cursor . getString ( column_index ) ;
84
- if ( filePath ) {
85
- 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 ( ) ;
86
88
}
87
89
}
88
90
}
89
- catch ( e ) {
90
- console . log ( e ) ;
91
- }
92
- finally {
93
- if ( cursor ) {
94
- 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
+ }
95
112
}
96
113
}
97
-
98
114
return undefined ;
115
+
99
116
}
100
117
101
118
private static isExternalStorageDocument ( uri : android . net . Uri ) {
0 commit comments