- 在項目的根目錄, 建立兩個目錄:
- 從剛纔下載的PhoneGap中複製cordova.js 到/assets/www目錄
- 從剛纔下載的PhoneGap中複製cordova.jar 到/libs目錄
- 從剛纔下載的PhoneGap中複製xml文到夾到/res 目錄
- M對Eclipse的src文件夾中的主Java文件進行少許調整:(以下圖)
- 將class的繼承類由 Activity改成DroidGap
- 將setContentView() 這一行替換爲super.loadUrl("file:///android_asset/www/index.html");
- 添加import com.phonegap.*;
- 移除 import android.app.Activity;
- 在這裏你可能會遇到Eclipse找不到cordova.jar的錯誤。在這種狀況下,右鍵單擊/libs文件夾找到Build Paths/ > Configure Build Paths。而後在Libraries標籤頁中添加cordova.jar到項目中。若是Eclipse不是很穩定,你須要點擊F5刷新一次項目。
- 右鍵單擊AndroidManifest.xml並選擇Open With > Text Editor。
- 將下面的權限設置拷貝到versionName以後:(以下圖)
<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" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
- Add android:configChanges="orientation|keyboardHidden" to the activity tag in AndroidManifest. (view image below)
- Add a second activity under you appliction tag in AndroidManifest. (view image below)
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden"> <intent-filter> </intent-filter> </activity>