下载最新版本的PhoneGap并解压,我们将使用其中的Android目录。下载地址:https://github.com/phonegap/phonegap/zipball/1.0.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" />在AndroidManifest的activity标签中添加
android:configChanges="orientation|keyboardHidden"
。 <!DOCTYPE HTML> <html> <head> <title>小地盘</title> <script type="text/javascript" charset="utf-8" src="phonegap.js"></script> </head> <body> <h1>你好, 小地盘。</h1> </body> </html>
MainActivity.java
package com.example.html5test; import android.os.Bundle; import com.phonegap.DroidGap; public class MainActivity extends DroidGap { String url = "file:///android_assets/www/index.html"; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.loadUrl(url); } }
修改MainActivity.java
package com.example.html5test; import android.app.Activity; import android.os.Bundle; import android.webkit.WebSettings; import android.webkit.WebView; public class MainActivity extends Activity { WebView mWebView; String url = "file:///android_assets/www/index.html"; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_main); WebView mWebView = (WebView) this.findViewById(R.id.webid); mWebView.loadUrl(url); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); } }
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.html5test.MainActivity$PlaceholderFragment" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <WebView android:id="@+id/webid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="100dp" /> </RelativeLayout>
测试结果:
http://awebird.com/blog/art/122
http://awebird.com/blog/art/190
http://www.csdn.net/article/a/2015-04-21/15823933
http://blog.csdn.net/kuangshazi515/article/details/7725624
http://www.cnblogs.com/charley_yang/archive/2011/02/28/1967559.html
具体问题列出来了,还没有解决,大牛们一起讨论帮忙解决。