Explorar el Código

Merge pull request #149 from studiozeffa/fix/cp-illegal-callback-invocation

Fix 'Illegal Callback Invocation' Android exception
Travis Nuttall hace 6 años
padre
commit
d07567396b
No account linked to committer's email address
Se han modificado 1 ficheros con 10 adiciones y 3 borrados
  1. 10
    3
      android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

+ 10
- 3
android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java Ver fichero

548
         path = normalizePath(path);
548
         path = normalizePath(path);
549
         InputStream in = null;
549
         InputStream in = null;
550
         OutputStream out = null;
550
         OutputStream out = null;
551
+        String message = "";
551
 
552
 
552
         try {
553
         try {
553
             if(!isPathExists(path)) {
554
             if(!isPathExists(path)) {
571
                 out.write(buf, 0, len);
572
                 out.write(buf, 0, len);
572
             }
573
             }
573
         } catch (Exception err) {
574
         } catch (Exception err) {
574
-            callback.invoke(err.getLocalizedMessage());
575
+            message += err.getLocalizedMessage();
575
         } finally {
576
         } finally {
576
             try {
577
             try {
577
                 if (in != null) {
578
                 if (in != null) {
580
                 if (out != null) {
581
                 if (out != null) {
581
                     out.close();
582
                     out.close();
582
                 }
583
                 }
583
-                callback.invoke();
584
             } catch (Exception e) {
584
             } catch (Exception e) {
585
-                callback.invoke(e.getLocalizedMessage());
585
+                message += e.getLocalizedMessage();
586
             }
586
             }
587
         }
587
         }
588
+        // Only call the callback once to prevent the app from crashing
589
+        // with an 'Illegal callback invocation from native module' exception.
590
+        if (message != "") {
591
+            callback.invoke(message);
592
+        } else {
593
+            callback.invoke();
594
+        }
588
     }
595
     }
589
 
596
 
590
     /**
597
     /**