搭建PhoneGap for Android開發環境

來源:互聯網
上載者:User

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");


 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.