Build an android application environment using phonegap

Source: Internet
Author: User
  • 1. Requirements
    • Eclipse 3.4 +

    This tutorial also has another version that does not use eclipse. For details, refer to here.

  • 2. Install SDK + phonegap

    Download and install eclipse classic.

    Download and install the android SDK.

    Download and install ADT plugin.

    Download the latest version of phonegap and decompress it. We will use the android directory.

  • 3. New Project Settings
    • Start eclipse and select "New> Android project" under "File ".

    • Under the project root directory, create two new directories:

      • /Libs
      • /Assets/WWW
    • Copy phonegap. js to/assets/www.
    • Copy phonegap. jar from the decompressed Android directory of phonegap to/libs.
    • Copy the entire XML directory (from the android directory decompressed by phonegap, including a plugins. XML) to/Res. [V1.0 RC2 or above]
    • Make a few adjustments to the main java files in the SRC folder of Eclipse: (for example)
      • Change the class inheritance from activity to droidgap
      • Replace setcontentview () with super. loadurl ("file: // android_asset/www/index.html ");
      • Add import com. phonegap .*;
      • Remove import Android. App. activity;

    • Here you may encounter errors where eclipse cannot find the phonegap-1.0.0.jar. In this case, right-click the/libs folder and find build paths/> Configure build paths. Then add the phonegap-1.0.0.jar to the project on the libraries tab. If eclipse is not very stable, you need to click F5 to refresh the project.
    • Right-click androidmanifest. xml and choose open with> text editor.
    • Copy the following permission settings to versionname: (for example)<supports-screens
      android:largeScreens="true"
      android:normalScreens="true"
      android:smallScreens="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.READ_PHONE_STATE" />
      <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.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" />

    • Add the following content to the androidmanifest activity Tag:android:configChanges="orientation|keyboardHidden". (For example)
  • 4. Hello World

    Create a new file named index.html In the "/assets/www”" directory and paste the following code:

    <!DOCTYPE HTML>
    <title>PhoneGap</title>
    <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
    <body>
    </body>

     

  • 5a. Deploy to Simulator
    • Right-click the project node, select Run as, and then click Android Application.
    • Eclipse requires you to select an appropriate AVD. If not set, you need to create an AVD.
  • 5b. Deploy to the device
    • Make sure that the USB debugging option is selected and the device is connected to the computer. (Settings> Applications> Development)
    • Right-click the project node, select Run as, and click Android Application.
  • Done!
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.