PhoneGap is a set of application development platforms that allow you to easily invoke native API interfaces and publish apps to the store using HTML5. The official said there are low cost, low development cycle, light weight and other advantages, which I can not prove temporarily, skip the table. But there is a cross-platform, but it is a clear advantage. Because it uses the html5+javascript pattern to develop the application. PhoneGap uses JavaScript to encapsulate the native API (ANDRIOD,IOS,WP8/7,WINRT) of several platforms and so on. In this case, porting from one platform to another only requires the HTML code and JS intact to take the past, packaging it. PhoneGap was later acquired by Adobe and then contributed to the open source community, now managed by Apache and renamed Cordova.
In order to transplant yesterday's HTML5 drawing board to the mobile device, I decided to use the PhoneGap platform, so as long as the writing side can be run more.
Today, we first set up the PHONEGAP environment under the andriod.
1. Download PhoneGap
Http://phonegap.com/install/recommended use of PhoneGap2.7.0
Extract it and find the Lib/android directory.
2. Create a new Andriod project under Eclipse, just like a regular project.
3. Create a new folder "www" under the assets Directory
Copy the cordova-2.6.0.js from the Lib/android directory to this directory. Copy the Cordova-2.6.0.jar to the Libs directory.
4. Create a new HTML file index.html in the WWW directory. Our interface is going to be built here.
The code for index is as follows:
The code is as follows:
<!doctype html>
<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.7.0.js" charset= "Utf-8" ></script>
<script type= "Text/javascript" >
Alert ("HELLO CORDOVA");
</script><body> </body>
5. Copy the XML folder under the Lib/android directory to res
6. Modify Androidmanifest.xml Add User rights
Add the following code at the top of the <manifest > tag
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"
/><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 {@Override
public void OnCreate (Bundle savedinstancestate)
{
Super.oncreate (savedinstancestate);
Super.
Loadurl("file:///android_asset/www/index.html");
}}
8.build there will be errors, because the front cordova-2.7.0.jar is not added to the buildpath inside. Add BuildPath.
The build went on.
Last run:
Such a phonegap andriod program will be taken care of. Transplant yesterday's HTML5 board tomorrow.