You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "ASF subversion and git services (JIRA)" <ji...@apache.org> on 2014/06/06 20:34:01 UTC

[jira] [Commented] (CB-6890) Android plugins which use pluginManager fields break on 4.0.x branch

    [ https://issues.apache.org/jira/browse/CB-6890?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14020184#comment-14020184 ] 

ASF subversion and git services commented on CB-6890:
-----------------------------------------------------

Commit 690824248cd745a44ba79b622b370d0b41cdbce0 in cordova-plugin-file-transfer's branch refs/heads/master from [~iclelland]
[ https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-file-transfer.git;h=6908242 ]

CB-6890: Fix pluginManager access for 4.0.x branch


> 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)