11package com .RNFetchBlob ;
22
3+ import android .app .Activity ;
34import android .content .Intent ;
45import android .net .Uri ;
6+ import android .util .Log ;
57
68import com .RNFetchBlob .Utils .RNFBCookieJar ;
9+ import com .facebook .react .bridge .ActivityEventListener ;
710import com .facebook .react .bridge .Callback ;
811import com .facebook .react .bridge .LifecycleEventListener ;
912import com .facebook .react .bridge .Promise ;
1518import com .facebook .react .bridge .WritableArray ;
1619import com .facebook .react .bridge .WritableMap ;
1720
21+ import java .util .HashMap ;
1822import java .util .Map ;
23+ import java .util .UUID ;
1924import java .util .concurrent .LinkedBlockingQueue ;
2025import java .util .concurrent .ThreadPoolExecutor ;
2126import java .util .concurrent .TimeUnit ;
2227
28+ import static android .app .Activity .RESULT_OK ;
29+ import static com .RNFetchBlob .RNFetchBlobConst .GET_CONTENT_INTENT ;
30+
2331public class RNFetchBlob extends ReactContextBaseJavaModule {
2432
2533 static ReactApplicationContext RCTContext ;
@@ -28,12 +36,28 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
2836 static LinkedBlockingQueue <Runnable > fsTaskQueue = new LinkedBlockingQueue <>();
2937 static ThreadPoolExecutor fsThreadPool = new ThreadPoolExecutor (2 , 10 , 5000 , TimeUnit .MILLISECONDS , taskQueue );
3038 static public boolean ActionViewVisible = false ;
39+ static HashMap <Integer , Promise > promiseTable = new HashMap <>();
3140
3241 public RNFetchBlob (ReactApplicationContext reactContext ) {
3342
3443 super (reactContext );
3544
3645 RCTContext = reactContext ;
46+ reactContext .addActivityEventListener (new ActivityEventListener () {
47+ @ Override
48+ public void onActivityResult (Activity activity , int requestCode , int resultCode , Intent data ) {
49+ if (requestCode == GET_CONTENT_INTENT && resultCode == RESULT_OK ) {
50+ Uri d = data .getData ();
51+ promiseTable .get (GET_CONTENT_INTENT ).resolve (d .toString ());
52+ promiseTable .remove (GET_CONTENT_INTENT );
53+ }
54+ }
55+
56+ @ Override
57+ public void onNewIntent (Intent intent ) {
58+
59+ }
60+ });
3761 }
3862
3963 @ Override
@@ -322,4 +346,16 @@ public void fetchBlobForm(ReadableMap options, String taskId, String method, Str
322346 new RNFetchBlobReq (options , taskId , method , url , headers , null , body , callback ).run ();
323347 }
324348
349+ @ ReactMethod
350+ public void getContentIntent (String mime , Promise promise ) {
351+ Intent i = new Intent (Intent .ACTION_GET_CONTENT );
352+ if (mime != null )
353+ i .setType (mime );
354+ else
355+ i .setType ("*/*" );
356+ promiseTable .put (GET_CONTENT_INTENT , promise );
357+ this .getReactApplicationContext ().startActivityForResult (i , GET_CONTENT_INTENT , null );
358+
359+ }
360+
325361}
0 commit comments