我遇到了一个webview问题,可以通过app访问localStorage。我的index.html通知我的浏览器(即webview)不支持本地存储。如果您有任何建议..请查看我的代码:
Activity.java :
package com.exercise.AndroidHTML;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class AndroidHTMLActivity extends Activity {
WebView myBrowser;
;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myBrowser = (WebView)findViewById(R.id.mybrowser);
myBrowser.loadUrl("file:///android_asset/index.html");
WebSettings webSettings = myBrowser.getSettings();
//enable JavaScript in webview
webSettings.setJavaScriptEnabled(true);
//Enable and setup JS localStorage
webSettings.setDomStorageEnabled(true);
webSettings.setDatabaseEnabled(true);
}
}
的AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exercise.AndroidHTML"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AndroidHTMLActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
答案 0 :(得分:1)
setDatabasePath()方法在API级别19中已弃用。我建议您使用这样的存储区域设置:
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
webView.getSettings().setDatabasePath("/data/data/" + webView.getContext().getPackageName() + "/databases/");
}
答案 1 :(得分:0)
您可能必须设置数据库路径:
webView.getSettings()。setDatabasePath(“/ data / data /”+ webView.getContext()。getPackageName()+“/ databases /”);