Android本地存储 [英] Android local storage
本文介绍了Android本地存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对Webview有问题,该Webview可能通过应用程序访问localStorage.我的index.html通知我的浏览器(即Web视图)不支持本地存储.如果您有任何建议,请看一下我的代码:
I have a problem with a webview which may access to the localStorage by app. My index.html informs that local storage is'nt supported by my browser (ie. the webview). If you have any suggestion.. Please take a look at my code :
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>
推荐答案
您可能必须设置数据库路径:
You may have to set the database path:
webView.getSettings().setDatabasePath("/data/data/" + webView.getContext().getPackageName()+"/databases/");
webView.getSettings().setDatabasePath("/data/data/" + webView.getContext().getPackageName() + "/databases/");
这篇关于Android本地存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文