Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
4.0.0
-
None
-
None
Description
The field CordovaWebView.pluginManager was changed from a public field to a getter, getPluginManager(), for Cordova-Android v4.0.0. (to support pluggable webviews)
This means that code in plugins like this:
PluginManager pm = webView.pluginManager;
will break. However, the replacement code,
PluginManager pm = webView.getPluginManager();
will break on existing 3.x versions of Cordova.
The solution is to use reflection in the plugin to determine whether the method or the field is available, and to use the appropriate access method to get the plugin manager. This code works in both old and new versions of Cordova:
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) { } }