1.在eclipse中建立Android Project。
2.在項目的目錄下,建兩個檔案夾:
/libs
/assets/www
3.進入將剛剛下載並解壓的PhoneGap包裡Anroid目錄,我們需要的資源都在這個目錄下。
將cordova.js這個js檔案(具體名稱視當時下載的版本而定)copy到/assets/www目錄下,
把cordova-2.9.0.jar檔案copy到/libs目錄下。
再把xml目錄(xml整個檔案夾)copy到android項目的res目錄下。
4.在/assets/www下建立index.html檔案,內容:
DOCTYPE HTML> <html> <head> <title>PhoneGap</title> <script type="text/javascript" charset="utf-8" src="cordova.js"></script> </head> <body> <h1>Hello World</h1> </body> </html> <!DOCTYPE HTML><html> <head> <title>PhoneGap</title> <script type="text/javascript" charset="utf-8" src="cordova.js"></script> </head> <body> <h1>Hello World</h1> </body></html>
5.將以下許可權配置的xml內容copy到AndroidManifest.xml檔案中:
supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="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" /> <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" /> <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" />
6.將以下內容添加到AndroidManifest.xml檔案的activity標籤中:
android:configChanges="orientation|keyboardHidden
這是為了保證機器在橫豎屏切換的時候不會重新執行Activity的onCreate方法;
7、修改下src下的Java主檔案為:extends DroidGap
把setContentView()這行替換為super.loadUrl("file:///android_asset/www/index.html");