The first phonegap (Cordova) Application

Source: Internet
Author: User


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 needCodeTake it with JS intact, just pack it. Phonegap was later acquired by Adobe and then contributed to open-sourceCommunityNow 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:


 
 
<!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>

</head>
<body>

<h1>HTML5Paint</h1>
</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:


    <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


 




 
public class MainActivity extends DroidGap {

      @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            super.loadUrl("file:///android_asset/www/index.html");
        }

}


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:



 






This phonegap's andriod Program is done. 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.