First, you need to create an Android project in eclipse
Open Eclipse, open file->new->project
Select Android Application Project Click Next
Enter Project Name, the other two will be displayed automatically, the other options are on the line by default
followed by the default various options, next to the last step
Activity name is the activity class name
Layout name is the format file name
Create a name to complete.
Two. Change Android project to PhoneGap project
1. Create the WWW folder under the Assets folder in the left sidebar just created project root directory, create the index.html in the WWW folder, write any content.
2. Copy the cordova.js from the downloaded PhoneGap folder to the WWW folder,
3. Copy the Cordova-2.9.0.jar file to the root directory under the Libs folder
4. Expand the Mainactivity.java source file under Com.phonegap.helloworld in the SRC folder to make the following modifications (these two names differ according to the name of the project when they were created)
Package Com.phonegapbook.helloworld;
Import Android.os.Bundle;
Import org.apache.cordova.*;
public class Mainactivity extends Droidgap {//mainactivity is the name of this source file inherits Droidgap class
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Super.loadurl ("file:///android_asset/www/index.html");
}
}
Add import org.apache.cordova.*; is the Droidgap class in the previously copied Cordova-2.9.0.jar
public class Mainactivity extends droidgap{...} is to inherit the Droidgap class, not the default Actionbaractivity class
This changed from Android to PhoneGap project.
Three. Modify the XML file
Open the Androidmanifest.xml file under the root directory and change to the following code
<?xml version= "1.0" encoding= "Utf-8"?>
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
Package= "Com.phonegap.helloworld"
Android:versioncode= "1"
Android:versionname= "1.0" >
<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"/>
<uses-sdk
Android:minsdkversion= "8"
Android:targetsdkversion= "/>"
<application
android:allowbackup= "true"
android:icon= "@drawable/ic_launcher"
android:label= "@string/app_name"
android:theme= "@style/apptheme" >
<activity
android:name= ". Mainactivity "
android:label= "@string/app_name" >
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Note that the class name and the package name should correspond to the
Four. Test your application
Right-click index.html Select Run as->run configurations to open the following dialog box->target
Press to uncheck all Android virtual machine options and click Run to open the HelloWorld app on your phone (before connecting your phone to your computer).
Create an Android PhoneGap project