From 690824248cd745a44ba79b622b370d0b41cdbce0 Mon Sep 17 00:00:00 2001 From: Ian Clelland Date: Fri, 6 Jun 2014 14:27:57 -0400 Subject: [PATCH] CB-6890: Fix pluginManager access for 4.0.x branch --- src/android/FileTransfer.java | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/android/FileTransfer.java b/src/android/FileTransfer.java index 8c22e0d..01d22e0 100644 --- a/src/android/FileTransfer.java +++ b/src/android/FileTransfer.java @@ -28,6 +28,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.net.HttpURLConnection; import java.net.URLConnection; import java.security.cert.CertificateException; @@ -50,6 +53,7 @@ import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaPlugin; import org.apache.cordova.CordovaResourceApi; import org.apache.cordova.CordovaResourceApi.OpenForReadResult; +import org.apache.cordova.PluginManager; import org.apache.cordova.PluginResult; import org.apache.cordova.file.FileUtils; import org.json.JSONArray; @@ -795,7 +799,24 @@ public class FileTransfer extends CordovaPlugin { Log.d(LOG_TAG, "Saved file: " + target); // create FileEntry object - FileUtils filePlugin = (FileUtils)webView.pluginManager.getPlugin("File"); + Class webViewClass = webView.getClass(); + PluginManager pm = null; + try { + Method gpm = webViewClass.getMethod("getPluginManager"); + pm = (PluginManager) gpm.invoke(webView); + } catch (NoSuchMethodException e) { + } catch (IllegalAccessException e) { + } catch (InvocationTargetException e) { + } + if (pm == null) { + try { + Field pmf = webViewClass.getField("pluginManager"); + pm = (PluginManager)pmf.get(webView); + } catch (NoSuchFieldException e) { + } catch (IllegalAccessException e) { + } + } + FileUtils filePlugin = (FileUtils) pm.getPlugin("File"); if (filePlugin != null) { JSONObject fileEntry = filePlugin.getEntryForFile(file); if (fileEntry != null) {