gregm
gregm

Reputation: 12169

Do PhoneGap / Cordova javascript calls require CordovaWebView or DroidGap?

It is possible to call a PhoneGap javascript function from a plain WebView?

The following code does not seem to be enough to allow my html page to call PhoneGap functions. My function calls fail when my app uses WebView, but succeed when my app uses an activity that extends DroidGap.

    <script type="text/javascript" src="cordova-2.2.0.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" src="main.js"></script>
    <script type="text/javascript">
        app.initialize();
    </script>

Upvotes: 1

Views: 1753

Answers (2)

Andrew Trice
Andrew Trice

Reputation: 701

It is not possible to call PhoneGap functions from a normal web view. The code you are showing is from the initial project template for a new PhoneGap project - the initialize function setups up event handlers that get triggered by the ondeviceready event. The ondeviceready event is specific to PhoneGap applications. It does not exist within a normal web view. PhoneGap API functions will not work - you can only use the JavaScript APIs that are supported by the system web browser.

Upvotes: 0

Nilanchala
Nilanchala

Reputation: 5941

Yes it is possible to call a javascript function from a plain WebView. For that you need to write your own avaScriptInterface. Follow the link below for a sample

http://android-er.blogspot.in/2011/10/call-javascript-inside-webview-from.html

But, I am sure you cannot use the PhoneGap features using this method. If, you are looking for phonegap based solution, then you must extend your activity from DroidGap activity.

Upvotes: 1

Related Questions