Skip to content
This repository has been archived by the owner on Apr 2, 2018. It is now read-only.

Remove depreciated call to sendJavaScript for more recent method #40

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mysegfault
Copy link

No description provided.

@pencilcheck
Copy link

Does it work for iOS?

@mlynch
Copy link
Contributor

mlynch commented Dec 7, 2014

@tlancina will be digging into these issues in the next week or so.

On Sat, Dec 6, 2014 at 9:26 PM, Penn Su [email protected] wrote:

Does it work for iOS?


Reply to this email directly or view it on GitHub
#40 (comment)
.

Max Lynch
CEO and Co-founder
http://ionicframework.com/

@voliva
Copy link

voliva commented May 26, 2015

I tried to apply this patch, but it looks like webView.post and webview.evalutaeJavascript are not available in the last version of cordova-android (4.0.0)

@mysegfault
Copy link
Author

I'm using Cordova version 4.3.0 and it's working fine. This change is quite common on Cordova plugins, the same source code exists and works. Which error do you get and when ? Which Android SDK version do you have ?

@voliva
Copy link

voliva commented May 26, 2015

My cordova version is 5.0 and my cordova-android version is 4.0.0. Note that cordova lib differs from cordova android although we use both to build for Android. The last version of cordova-android is 4.0.3, and they are developing 4.1.0 now.
My Android SDK is API 21.

You can find your cordova-android version by looking at the top of your cordova.js file in the platform project (cat platforms/android/assets/www/cordova.js | grep PLATFORM_VERSION_BUILD_LABEL works for me)

@mysegfault
Copy link
Author

Ok i'm still using cordova-android 3.7.1 - for good reasons - but it shouldn't break the code anyway...

@voliva
Copy link

voliva commented May 26, 2015

Yes it does.. In this commit apache/cordova-android@087ec11 they refractored the way the WebView is loaded, and made CordovaWebView to act as an interface.
It looks like we have to go to org/apache/cordova/engine/SystemWebView.java to find those methods... probably we could just cast CordovaWebView. getEngine() and cast it to SystemWebView?
edit: Be careful though if a "plugin" changes the webview... like crosswalk.

@mysegfault
Copy link
Author

Other official plugins use "this.cordova.getActivity().runOnUiThread(new Runnable() { ..."
see: https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-inappbrowser.git;a=blob_plain;f=src/android/InAppBrowser.java;hb=HEAD

@voliva
Copy link

voliva commented May 26, 2015

Your solution still needs to use evaluateJavascript() from android.webkit.WebView

@mysegfault
Copy link
Author

Got it!
I recently updated to Cordova 5.1.1 so i could fix this error. You should see the new commit for this pull request, the solution is coming from other official Cordova plugins. It's compiling with gradle now.

@homer-jay
Copy link

I got here from Google and don't know a thing about what this repo is about. But the last commit for Cordova 5 (3a0d5e3) doesn't make any sense. Not only you reverted back to sendJavascript, but also there's a useless check for KitKat that is not needed at all. sendJavascript is deprecated in CordovaWebView, but whether it works or not does not depend on the Android OS version.

@mysegfault
Copy link
Author

The test for the API version is mandatory because it's the old style method for sending back JS commands. Better to leave it or it won't compile for these old devices. This commit make the JS work for all versions, this code is also used on many other cordova plugins. It could be imrproved but should still work for all devices.

@homer-jay
Copy link

@mysegfault sendJavascript does indeed compile before KitKat (but will throw an exception during plugin initialization with the last Cordova 5.1). What I mean is, why not just using loadUrl for all OS versions? I think the KitKat check is a carryover from the older code when you needed to call evaluateJavascript.

@mysegfault
Copy link
Author

loadUrl is depreciated for security purposes, you shouldn't use this method on recent devices. I think there is now a cleaner method for what we need, by keeping the reference to the callbackContext and use the sendPluginResult method.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants