Application details based on the first PhoneGap (cordova)

Source: Internet
Author: User

Comments: PhoneGap is a set of application development platforms that allow you to use HTML5 to easily call local APIs and publish applications to stores. The official saying is that there are advantages such as low cost, low development cycle, and lightweight, which cannot be proved temporarily. However, there is a cross-platform architecture, but it has obvious advantages. Because it adopts the HTML5 + JavaScript mode to develop applications

PhoneGap is an application development platform that allows you to use HTML5 to easily call local APIs and publish applications to stores. The official saying is that there are advantages such as low cost, low development cycle, and lightweight, which cannot be proved temporarily. However, there is a cross-platform architecture, but it has obvious advantages. Because it adopts the HTML5 + JavaScript mode to develop applications. PhoneGap uses JavaScript to encapsulate local APIs (Andriod, IOS, WP8/7, WINRT) on several platforms .. In this way, you only need to pack the HTML code and JS from one platform to another. PhoneGap was later acquired by Adobe and then contributed to the open-source community. Now it is managed by Apache and renamed cordova.

To port the html5 palette to a mobile device yesterday, I decided to use the phoneGap platform, so that I could run it more when writing it.

Today, we first set up the phoneGap environment under Andriod.

1. Download phoneGap

Http://phonegap.com/download/#autodownload

Decompress the package and find the lib/android directory.

2. Create an Andriod project under eclipse, which is the same as a common project.

3. Create a folder "www" under the assets Directory"

Copy the cordova-2.6.0.js under the lib/android directory to this directory. Copy cordova-2.6.0.jar to the libs directory.

4.create an HTML file index.html under the wwwdirectory. Our interface will be created here.

The index code is as follows:

The Code is as follows:
<! Doctype html>
<Html>
<Head>
<Meta name = "viewport" content = "user-scalable = no, initial-scale = 1, maximum-scale = 1, minimum-scale = 1, width = device-width, height = device-height, target-densitydpi = device-dpi "/>
<Title> HTML5Paint </title>
<Script type = "text/javascript" src = "cordova-2.6.0.js" charset = "UTF-8"> </script>
<Script type = "text/javascript">
Alert ("hello cordova ");
</Script> </p> <Body> </p> </Body>
</Html>

5. Copy the xml folder in the lib/android directory to the res directory.

6. Modify AndroidManifest. xml to Add User Permissions

Add the following code to the front of the <manifest> label:

The Code is as follows:
<Supports-screens
Android: largeScreens = "true"
Android: normalScreens = "true"
Android: smallScreens = "true"
Android: xlargeScreens = "true"
Android: resizeable = "true"
Android: anyDensity = "true"
/> </P> <uses-permission android: name = "android. permission. CAMERA"/>
<Uses-permission android: name = "android. permission. VIBRATE"/>
<Uses-permission android: name = "android. permission. ACCESS_COARSE_LOCATION"/>
<Uses-permission android: name = "android. permission. ACCESS_FINE_LOCATION"/>
<Uses-permission android: name = "android. permission. ACCESS_LOCATION_EXTRA_COMMANDS"/>
<Uses-permission android: name = "android. permission. INTERNET"/>
<Uses-permission android: name = "android. permission. RECEIVE_SMS"/>
<Uses-permission android: name = "android. permission. RECORD_AUDIO"/>
<Uses-permission android: name = "android. permission. RECORD_VIDEO"/>
<Uses-permission android: name = "android. permission. MODIFY_AUDIO_SETTINGS"/>
<Uses-permission android: name = "android. permission. READ_CONTACTS"/>
<Uses-permission android: name = "android. permission. WRITE_CONTACTS"/>
<Uses-permission android: name = "android. permission. WRITE_EXTERNAL_STORAGE"/>
<Uses-permission android: name = "android. permission. ACCESS_NETWORK_STATE"/>
<Uses-permission android: name = "android. permission. GET_ACCOUNTS"/>
<Uses-permission android: name = "android. permission. BROADCAST_STICKY"/>

7. Modify MainAcivity. java

The Code is as follows:
Public class MainActivity extends DroidGap {</p> <p> @ Override
Public void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
Super. loadUrl ("file: // android_asset/www/index.html ");
} </P> <p>}

8. build will have an error, this is because the cordova-2.6.0.jar is not added to buildpath. Add buildpath.

Continue to build.

Run the following command:

 

In this way, the Andriod program of phonegap is finished. We will port the HTML5 canvas from yesterday tomorrow.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.