Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

278 lines (257 sloc) 13.0 kb
<!DOCTYPE html>
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
--><html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
<meta name="generator" content="joDoc">
<title>PhoneGap API Documentation</title>
<link rel="stylesheet" type="text/css" href="index.css">
<link rel="stylesheet" type="text/css" href="mobile.css" media="only screen and (max-device-width: 1024px)">
<link rel="stylesheet" type="text/css" href="prettify/prettify.css">
<div id="header">
<h1><a href="index.html">PhoneGap Documentation</a></h1>
<select><optgroup label="English" value="en">
<option value="edge">edge</option>
<option value="2.9.0rc1">2.9.0rc1</option>
<option selected value="2.9.0">2.9.0</option>
<option value="2.8.0">2.8.0</option>
<option value="2.7.0rc1">2.7.0rc1</option>
<option value="2.7.0">2.7.0</option>
<option value="2.6.0rc1">2.6.0rc1</option>
<option value="2.6.0">2.6.0</option>
<option value="2.5.0rc1">2.5.0rc1</option>
<option value="2.5.0">2.5.0</option>
<option value="2.4.0rc1">2.4.0rc1</option>
<option value="2.4.0">2.4.0</option>
<option value="2.3.0rc2">2.3.0rc2</option>
<option value="2.3.0rc1">2.3.0rc1</option>
<option value="2.3.0">2.3.0</option>
<option value="2.2.0rc2">2.2.0rc2</option>
<option value="2.2.0rc1">2.2.0rc1</option>
<option value="2.2.0">2.2.0</option>
<option value="2.1.0rc2">2.1.0rc2</option>
<option value="2.1.0rc1">2.1.0rc1</option>
<option value="2.1.0">2.1.0</option>
<option value="2.0.0rc1">2.0.0rc1</option>
<option value="2.0.0">2.0.0</option>
<option value="1.9.0rc1">1.9.0rc1</option>
<option value="1.9.0">1.9.0</option>
<option value="1.8.1">1.8.1</option>
<option value="1.8.0rc1">1.8.0rc1</option>
<option value="1.8.0">1.8.0</option>
<option value="1.7.0rc1">1.7.0rc1</option>
<option value="1.7.0">1.7.0</option>
<option value="1.6.1">1.6.1</option>
<option value="1.6.0rc1">1.6.0rc1</option>
<option value="1.6.0">1.6.0</option>
<option value="1.5.0rc1">1.5.0rc1</option>
<option value="1.5.0">1.5.0</option>
<option value="1.4.1">1.4.1</option>
<option value="1.4.0rc1">1.4.0rc1</option>
<option value="1.4.0">1.4.0</option>
<option value="1.3.0">1.3.0</option>
<option value="1.2.0">1.2.0</option>
<option value="1.1.0">1.1.0</option>
<option value="1.0.0rc3">1.0.0rc3</option>
<option value="1.0.0rc2">1.0.0rc2</option>
<option value="1.0.0rc1">1.0.0rc1</option>
<option value="1.0.0">1.0.0</option>
<option value="0.9.6">0.9.6</option>
<option value=""></option>
<option value="0.9.5">0.9.5</option>
<option value="0.9.4">0.9.4</option>
<option value="0.9.3">0.9.3</option>
<option value="0.9.2">0.9.2</option>
<optgroup label="Español" value="es"><option value="1.0.0">1.0.0</option></optgroup>
<optgroup label="Français" value="fr">
<option value="1.3.0">1.3.0</option>
<option value="1.2.0">1.2.0</option>
<option value="1.1.0">1.1.0</option>
<optgroup label="Japanese" value="jp">
<option value="2.2.0">2.2.0</option>
<option value="2.1.0">2.1.0</option>
<option value="2.0.0">2.0.0</option>
<option value="1.9.0">1.9.0</option>
<option value="1.8.1">1.8.1</option>
<option value="1.7.0">1.7.0</option>
<option value="0.9.5">0.9.5</option>
<optgroup label="Korean" value="kr"><option value="2.0.0">2.0.0</option></optgroup></select></small>
<div id="subheader">
<h1>Embedding Cordova WebView on Android</h1>
<small><select><option value="Embedding%2520Cordova%2520WebView%2520on%2520Android">Embedding Cordova WebView on Android</option>
<option value="Embedding%20Cordova%20WebView%20on%20Android_prerequisites">      - Prerequisites</option>
<option value="Embedding%20Cordova%20WebView%20on%20Android_guide_to_using_cordovawebview_in_an_android_project">      - Guide to using CordovaWebView in an Android Project</option></select></small>
<div id="sidebar">
<div class="vertical_divider"></div>
<h1>API Reference</h1>
<li><a href="">Accelerometer</a></li>
<li><a href="">Camera</a></li>
<li><a href="">Capture</a></li>
<li><a href="">Compass</a></li>
<li><a href="">Connection</a></li>
<li><a href="">Contacts</a></li>
<li><a href="">Device</a></li>
<li><a href="">Events</a></li>
<li><a href="">File</a></li>
<li><a href="">Geolocation</a></li>
<li><a href="">Globalization</a></li>
<li><a href="">InAppBrowser</a></li>
<li><a href="">Media</a></li>
<li><a href="">Notification</a></li>
<li><a href="">Splashscreen</a></li>
<li><a href="">Storage</a></li>
<li><a href="">Overview</a></li>
<li><a href="">Platform Guides</a></li>
<li><a href="">The Cordova Command-line Interface</a></li>
<li><a href="">Command-Line Usage</a></li>
<li><a href="">Privacy Guide</a></li>
<li><a href="">Upgrading Guides</a></li>
<li><a href="">Project Settings</a></li>
<li><a href="">Plugin Development Guide</a></li>
<li><a href="">Domain Whitelist Guide</a></li>
<li><a href="">Embedding WebView</a></li>
<li><a href="_index.html">Keyword Index</a></li>
<div id="scrollable">
<div id="content">
<h1><a name="Embedding%20Cordova%20WebView%20on%20Android">Embedding Cordova WebView on Android</a></h1>
<p>Beginning in Cordova 1.9, with the assistance of the
<code>CordovaActivity</code>, you can use Cordova as a component in a larger
native Android application. Android refers to this component as the
<code>CordovaWebView</code>. New Cordova-based applications from 1.9 onwards use
the <code>CordovaWebView</code> as its main view, regardless of whether the
legacy <code>DroidGap</code> approach is used.</p>
<p>If you're unfamiliar with Android application development, please read
the <a href="">Android Platform Guide</a> to developing a Cordova Application before
attempting to include a WebView. It's not the main way to author
Android Cordova applications. These instructions are currently manual,
but may be eventually be automated.</p>
<a name="Embedding%20Cordova%20WebView%20on%20Android_prerequisites">Prerequisites</a>
<strong>Cordova 1.9</strong> or greater</li>
<li>Android SDK updated with 15</li>
<a name="Embedding%20Cordova%20WebView%20on%20Android_guide_to_using_cordovawebview_in_an_android_project">Guide to using CordovaWebView in an Android Project</a>
<li>Use <code>bin/create</code> to fetch the <code>commons-codec-1.6.jar</code> file.</li>
<code>cd</code> into <code>/framework</code> and run <code>ant jar</code> to build the cordova jar. It creates the .jar file formed as <code>cordova-x.x.x.jar</code> in the <code>/framework</code> folder.</li>
<li>Copy the cordova jar into your Android project's <code>/libs</code> directory.</li>
<p>Edit your application's <code>main.xml</code> file (under <code>/res/xml</code>) to look like the following, with the <code>layout_height</code>, <code>layout_width</code> and <code>id</code> modified to suit your application:</p>
<pre class="prettyprint"><code>&lt;org.apache.cordova.CordovaWebView
android:layout_height="match_parent" /&gt;
<p>Modify your activity so that it implements the <code>CordovaInterface</code>. You should implement the included methods. You may wish to copy them from <code>/framework/src/org/apache/cordova/</code>, or implement them on your own. The code fragment below shows a basic application that uses the interface. Note how the referenced view id matches the <code>id</code> attribute specified in the XML fragment shown above:</p>
<pre class="prettyprint"><code>public class CordovaViewTestActivity extends Activity implements CordovaInterface {
CordovaWebView cwv;
/* Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
cwv = (CordovaWebView) findViewById(;
If you use the camera, you should also implement this:
public void setActivityResultCallback(CordovaPlugin plugin) {
this.activityResultCallback = plugin;
<li>Launch an activity for which you would like a result when it finished. When this activity exits,</li>
<li>your onActivityResult() method is called.
<li>@param command The command object</li>
<li>@param intent The intent to start</li>
<p>@param requestCode The request code that is passed to callback to identify the activity
public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode) {
this.activityResultCallback = command;
this.activityResultKeepRunning = this.keepRunning;</p>
<p>// If multitasking turned on, then disable it for activities that return results
if (command != null) {
this.keepRunning = false;
<p>// Start activity
super.startActivityForResult(intent, requestCode);
<li>Called when an activity you launched exits, giving you the requestCode you started it with,</li>
<li>the resultCode it returned, and any additional data from it.
<li>@param requestCode The request code originally supplied to startActivityForResult(),</li>
<li>allowing you to identify who this result came from.</li>
<li>@param resultCode The integer result code returned by the child activity through its setResult().</li>
<p>@param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
CordovaPlugin callback = this.activityResultCallback;
if (callback != null) {
callback.onActivityResult(requestCode, resultCode, intent);
<p>Finally, remember to add the thread pool, otherwise the plugins have no threads to run on:</p>
public ExecutorService getThreadPool() {
return threadPool;
<li><p>Copy your application's HTML and JavaScript files to your Android project's <code>/assets/www</code> directory.</p></li>
<li>Copy <code>cordova.xml</code> and <code>plugins.xml</code> from <code>/framework/res/xml</code> to your project's <code>/res/xml</code> folder.</li>
<!-- Functionality and Syntax Highlighting -->
<script type="text/javascript" src="index.js"></script><script type="text/javascript" src="prettify/prettify.js"></script>
Jump to Line
Something went wrong with that request. Please try again.