You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Ian Clelland (JIRA)" <ji...@apache.org> on 2014/06/06 20:28:02 UTC
[jira] [Created] (CB-6890) Android plugins which use pluginManager
fields break on 4.0.x branch
Ian Clelland created CB-6890:
--------------------------------
Summary: Android plugins which use pluginManager fields break on 4.0.x branch
Key: CB-6890
URL: https://issues.apache.org/jira/browse/CB-6890
Project: Apache Cordova
Issue Type: Bug
Components: Android, Plugin File, Plugin File Transfer, Plugin Media Capture
Affects Versions: 4.0.0
Reporter: Ian Clelland
Assignee: Ian Clelland
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:
{code}
PluginManager pm = webView.pluginManager;
{code}
will break. However, the replacement code,
{code}
PluginManager pm = webView.getPluginManager();
{code}
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:
{code}
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) {
}
}
{code}
--
This message was sent by Atlassian JIRA
(v6.2#6252)