[ https://issues.apache.org/jira/browse/CB-5756?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Ian Clelland resolved CB-5756. ------------------------------ Resolution: Fixed Fixed in dev branch. > InAppBrowser example fails on Android 4.4 > ----------------------------------------- > > Key: CB-5756 > URL: https://issues.apache.org/jira/browse/CB-5756 > Project: Apache Cordova > Issue Type: Bug > Components: Android, Plugin InAppBrowser > Affects Versions: 3.3.0 > Environment: Android 4.4 > Reporter: Marcus Pridham > Assignee: Ian Clelland > > 1. Create cordova project and add InAppBrowser plugin > 2. Replace index.html contents with the Full Example for executeScript in > the API docs at > http://cordova.apache.org/docs/en/3.3.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser > 3. Build run the application. > 4. When the InAppBrowser loads the it displays the string > http://cordova.apache.org/images/cordova_bot.png. > The example is suppose to load the Apache site and replace the logo with the > cordova bot. If you open the AndroidManifest.xml and change the > targetSdkVersion from 19 to 18 it works as expected. > The problems seems to be caused by a change in behaviour in 4.4 with using > loadUrl("javascript:..."). See the loadUrl method in > https://android.googlesource.com/platform/frameworks/webview/+/android-4.4_r1.1/chromium/java/com/android/webview/chromium/WebViewChromium.java. > If the target sdk is kitkat the result of the JS Url replaces the content > of the current page... > The fix seems to be to use a new 4.4 method to the webview called > evaluateJavaScript. > http://developer.android.com/reference/android/webkit/WebView.html#evaluateJavascript(java.lang.String,%20android.webkit.ValueCallback<java.lang.String>) > In InAppBrowser.java: > Change this: > {code} > final String finalScriptToInject = scriptToInject; > // This action will have the side-effect of blurring the currently > focused element > this.cordova.getActivity().runOnUiThread(new Runnable() { > @Override > public void run() { > inAppWebView.loadUrl("javascript:" + finalScriptToInject); > } > }); > {code} > > To: > > {code} > final String finalScriptToInject = scriptToInject; > > // This action will have the side-effect of blurring the > currently focused element > this.cordova.getActivity().runOnUiThread(new Runnable() { > @Override > public void run() { > if > (cordova.getActivity().getApplicationInfo().targetSdkVersion < > Build.VERSION_CODES.KITKAT) > { > inAppWebView.loadUrl("javascript:" + > finalScriptToInject); > } else { > > inAppWebView.evaluateJavascript(finalScriptToInject, null); > } > } > }); > {code} > > > I haven't tried any other plugins but it might be neccessary to change other > plugins to use evaluateJavascript instead of loadUrl("javascript:..."). -- This message was sent by Atlassian JIRA (v6.1.5#6160)