1. Download PhoneGap (I used or cordova-1.5.0.jar)
http://phonegap.com/download/#autodownload
Extract it and find the Lib/android directory.
2. Create a new folder "www" under the assets Directory
3. Create a new HTML file index.html in the WWW directory. Our interface is going to be built here.
4. Copy the XML folder under the Lib/android directory to res
5. Modify Androidmanifest.xml Add User rights
1<supports-Screens2Android:largescreens= "true"3Android:normalscreens= "true"4Android:smallscreens= "true"5Android:resizeable= "true"6Android:anydensity= "true"7/>8<uses-permission android:name= "Android.permission.CAMERA"/>9<uses-permission android:name= "Android.permission.VIBRATE"/>Ten<uses-permission android:name= "Android.permission.ACCESS_COARSE_LOCATION"/> One<uses-permission android:name= "Android.permission.ACCESS_FINE_LOCATION"/> A<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"/> the<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"/> at<uses-permission android:name= "Android.permission.FLASHLIGHT"/> -<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
6. Modify Mainacivity.java
1 Public classDemoactivityextendsDroidgap {2 /**Called when the activity is first created.*/3 @Override4 Public voidonCreate (Bundle savedinstancestate) {5 Super. OnCreate (savedinstancestate);6 Super. Setintegerproperty ("SplashScreen", R.drawable.splash);8 //HTML file load slow, set timeout time9 Super. Setintegerproperty ("Loadurltimeoutvalue", 120000);Ten Super. Loadurl ("file:///android_asset/www/index.html"); One } A}
8.e.g.
1) Declare a a tag:
1 <a href= "#" data-icon= "check" id= "photo" > Photo </a>
2) Initialize the A-tag tap event:
1 $ ("#photo"). Live ("tap", Getphoto);
3) Tap event:
1 functionGetphoto () {3 if(!Navigator.camera) {4Alert ("Camera can not use");5 return;6 }7Navigator.camera.getPicture (onsuccess, Onfail, {quality:50, DestinationType:Camera.DestinationType.FILE_URI});8 9 functiononsuccess (imageData) {Ten //alert ("Camer successful!!!"); One //alert (imageData); A varnewnote=$ ("#newNote"); - varSrc=ImageData; - //var src= "data:image/jpeg;base64," + imageData; the varimg=$ ("#myPhoto"); -Img.attr ("src", SRC); -IMG.CSS ("Display", "block"); - //var img= " + //newnote.append (IMG); -Newnote.listview ("Refresh"); A } at - functiononfail (message) { -Alert (' Carema Failed because: ' +message); - } - in}
Andriod PhoneGap Getting Started