6
6
import android .content .pm .PackageManager ;
7
7
import android .net .Uri ;
8
8
import android .os .Build ;
9
+
9
10
import androidx .core .content .FileProvider ;
11
+
10
12
import android .util .SparseArray ;
11
13
import android .content .ActivityNotFoundException ;
12
14
30
32
import okhttp3 .OkHttpClient ;
31
33
32
34
import javax .annotation .Nullable ;
35
+
33
36
import java .io .File ;
34
37
import java .util .Map ;
35
38
import java .util .concurrent .LinkedBlockingQueue ;
@@ -44,12 +47,12 @@ public class ReactNativeBlobUtil extends ReactContextBaseJavaModule {
44
47
private final OkHttpClient mClient ;
45
48
46
49
static ReactApplicationContext RCTContext ;
47
- private static LinkedBlockingQueue <Runnable > taskQueue = new LinkedBlockingQueue <>();
48
- private static ThreadPoolExecutor threadPool = new ThreadPoolExecutor (5 , 10 , 5000 , TimeUnit .MILLISECONDS , taskQueue );
50
+ private static final LinkedBlockingQueue <Runnable > taskQueue = new LinkedBlockingQueue <>();
51
+ private static final ThreadPoolExecutor threadPool = new ThreadPoolExecutor (5 , 10 , 5000 , TimeUnit .MILLISECONDS , taskQueue );
49
52
static LinkedBlockingQueue <Runnable > fsTaskQueue = new LinkedBlockingQueue <>();
50
- private static ThreadPoolExecutor fsThreadPool = new ThreadPoolExecutor (2 , 10 , 5000 , TimeUnit .MILLISECONDS , taskQueue );
53
+ private static final ThreadPoolExecutor fsThreadPool = new ThreadPoolExecutor (2 , 10 , 5000 , TimeUnit .MILLISECONDS , taskQueue );
51
54
private static boolean ActionViewVisible = false ;
52
- private static SparseArray <Promise > promiseTable = new SparseArray <>();
55
+ private static final SparseArray <Promise > promiseTable = new SparseArray <>();
53
56
54
57
public ReactNativeBlobUtil (ReactApplicationContext reactContext ) {
55
58
@@ -64,7 +67,7 @@ public ReactNativeBlobUtil(ReactApplicationContext reactContext) {
64
67
reactContext .addActivityEventListener (new ActivityEventListener () {
65
68
@ Override
66
69
public void onActivityResult (Activity activity , int requestCode , int resultCode , Intent data ) {
67
- if (requestCode == GET_CONTENT_INTENT && resultCode == RESULT_OK ) {
70
+ if (requestCode == GET_CONTENT_INTENT && resultCode == RESULT_OK ) {
68
71
Uri d = data .getData ();
69
72
promiseTable .get (GET_CONTENT_INTENT ).resolve (d .toString ());
70
73
promiseTable .remove (GET_CONTENT_INTENT );
@@ -142,7 +145,7 @@ public void actionViewIntent(String path, String mime, @Nullable String chooserT
142
145
try {
143
146
this .getReactApplicationContext ().startActivity (intent );
144
147
promise .resolve (true );
145
- } catch (ActivityNotFoundException ex ) {
148
+ } catch (ActivityNotFoundException ex ) {
146
149
promise .reject ("ENOAPP" , "No app installed for " + mime );
147
150
}
148
151
}
@@ -152,7 +155,7 @@ public void actionViewIntent(String path, String mime, @Nullable String chooserT
152
155
153
156
@ Override
154
157
public void onHostResume () {
155
- if (ActionViewVisible )
158
+ if (ActionViewVisible )
156
159
promise .resolve (null );
157
160
RCTContext .removeLifecycleEventListener (this );
158
161
}
@@ -168,7 +171,7 @@ public void onHostDestroy() {
168
171
}
169
172
};
170
173
RCTContext .addLifecycleEventListener (listener );
171
- } catch (Exception ex ) {
174
+ } catch (Exception ex ) {
172
175
promise .reject ("EUNSPECIFIED" , ex .getLocalizedMessage ());
173
176
}
174
177
}
@@ -280,13 +283,13 @@ public void scanFile(final ReadableArray pairs, final Callback callback) {
280
283
@ Override
281
284
public void run () {
282
285
int size = pairs .size ();
283
- String [] p = new String [size ];
284
- String [] m = new String [size ];
285
- for (int i = 0 ; i < size ;i ++) {
286
+ String [] p = new String [size ];
287
+ String [] m = new String [size ];
288
+ for (int i = 0 ; i < size ; i ++) {
286
289
ReadableMap pair = pairs .getMap (i );
287
- if (pair .hasKey ("path" )) {
290
+ if (pair .hasKey ("path" )) {
288
291
p [i ] = pair .getString ("path" );
289
- if (pair .hasKey ("mime" ))
292
+ if (pair .hasKey ("mime" ))
290
293
m [i ] = pair .getString ("mime" );
291
294
else
292
295
m [i ] = null ;
@@ -308,8 +311,8 @@ public void run() {
308
311
}
309
312
310
313
/**
311
- * @param path Stream file path
312
- * @param encoding Stream encoding, should be one of `base64`, `ascii`, and `utf8`
314
+ * @param path Stream file path
315
+ * @param encoding Stream encoding, should be one of `base64`, `ascii`, and `utf8`
313
316
* @param bufferSize Stream buffer size, default to 4096 or 4095(base64).
314
317
*/
315
318
@ ReactMethod
@@ -375,7 +378,7 @@ public void fetchBlobForm(ReadableMap options, String taskId, String method, Str
375
378
@ ReactMethod
376
379
public void getContentIntent (String mime , Promise promise ) {
377
380
Intent i = new Intent (Intent .ACTION_GET_CONTENT );
378
- if (mime != null )
381
+ if (mime != null )
379
382
i .setType (mime );
380
383
else
381
384
i .setType ("*/*" );
@@ -385,15 +388,14 @@ public void getContentIntent(String mime, Promise promise) {
385
388
}
386
389
387
390
@ ReactMethod
388
- public void addCompleteDownload (ReadableMap config , Promise promise ) {
391
+ public void addCompleteDownload (ReadableMap config , Promise promise ) {
389
392
DownloadManager dm = (DownloadManager ) RCTContext .getSystemService (RCTContext .DOWNLOAD_SERVICE );
390
- if (config == null || !config .hasKey ("path" ))
391
- {
393
+ if (config == null || !config .hasKey ("path" )) {
392
394
promise .reject ("EINVAL" , "ReactNativeBlobUtil.addCompleteDownload config or path missing." );
393
395
return ;
394
396
}
395
397
String path = ReactNativeBlobUtilFS .normalizePath (config .getString ("path" ));
396
- if (path == null ) {
398
+ if (path == null ) {
397
399
promise .reject ("EINVAL" , "ReactNativeBlobUtil.addCompleteDownload can not resolve URI:" + config .getString ("path" ));
398
400
return ;
399
401
}
@@ -409,8 +411,7 @@ public void addCompleteDownload (ReadableMap config, Promise promise) {
409
411
config .hasKey ("showNotification" ) && config .getBoolean ("showNotification" )
410
412
);
411
413
promise .resolve (null );
412
- }
413
- catch (Exception ex ) {
414
+ } catch (Exception ex ) {
414
415
promise .reject ("EUNSPECIFIED" , ex .getLocalizedMessage ());
415
416
}
416
417
0 commit comments