1.新建工程PhoneGapHi
2.PhoneGapHi 工程目录
3.解压从官网上下载的包phonegap-2.9.0.zip
phonegap-2.9.0\phonegap-2.9.0\lib\android\example\libs\cordova-2.9.0.jar 把这个jar复制到
4.修改com.example.phonegaphi.MainActivity.java类 改为
package com.example.phonegaphi; import org.apache.cordova.DroidGap; import android.os.Bundle; import android.view.Menu; public class MainActivity extends DroidGap { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.loadUrl("file:///android_asset/www/index.html"); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }5.assets 文件下新建 www 文件夹 下面建index.html
index.html 代码如下:
<!DOCTYPE HTML> <html> <head> <title>PhoneGap</title> <script type="text/javascript" charset="utf-8" src="cordova.js"></script> </head> <body> <h1>Hi Phone Gap</h1> </body> </html>
复制到项目下的www文件夹中
6.把phonegap-2.9.0\phonegap-2.9.0\lib\android\example\res xml 文件夹复制到 项目的res 下
7.修改文件 AndroidManifest.xml 为
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.phonegaphi" android:versionCode="1" android:versionName="1.0" > <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" /> <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="18" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.phonegaphi.MainActivity" android:configChanges="orientation|keyboardHidden" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.phonegap.DroidGap" android:configChanges="orientation|keyboardHidden" android:label="@string/app_name" > <intent-filter> </intent-filter> </activity> </application> </manifest>
OK了累死这一下午。