Prerequisites: The Android SDK and ADT have been installed in eclipse.
1. Download PhoneGap, unzip.
2. Create a new Android project with Eclipse.
3. Copy the Phonegap-1.0.0.js from the Android folder in the PhoneGap unzip package to the/assets/www/directory of the Android project.
4. Copy the Phonegap-1.0.0.jar from the Android folder in the PhoneGap unzip package to the/libs directory of the Android project.
5. Create a new index.html in the/assets/www/directory with the following contents:
|
<! DOCTYPE html>
<title>PhoneGap</title>
<script type= "Text/javascript" charset= "Utf-8" src= "Phonegap-1.0.0.js" ></script>
<body>
</body>
|
6. Copy the following configuration permissions XML to the <application> label of the Androidmanifest.xml file.
|
<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"/>
<uses-permission android:name= "Android.permission.GET_ACCOUNTS"/>
<supports-screens
Android:anydensity= "true"
Android:largescreens= "true"
Android:normalscreens= "true"
Android:resizeable= "true"
Android:smallscreens= "true"/>
|
7. Add the following to the Activity tab of the Androidmanifest.xml file:
Android:configchanges= "Orientation|keyboardhidden
This is to ensure that the machine does not re-execute the activity's OnCreate method when switching between the two screens.
8. Locate the Libs directory in the newly created Android project and right-click on the Phonegap-1.0.0.jar and select Build Path->add to build Path.
9. Modify the Mainactivty in Android so that it inherits to Droidgap and modify its OnCreate method as follows:
|
public class Mainactivity extends Droidgap {
@Override public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate); Super.oncreate (savedinstancestate);
Super.loadurl ("file:///android_asset/www/index.html");
} |
10.OK, now running the Android project, you can see the content of the index.html we just built.