gpt4 book ai didi

Android WebView 本地存储

转载 作者:行者123 更新时间:2023-11-29 15:21:53 26 4
gpt4 key购买 nike

我正在尝试获取在 Android WebView(Webkit、ChromeClient)中运行的 HTML5 localStorage 示例。但是我没有运气。一切都在手机浏览器上运行,而不是在 WebView 上运行。

Activity :

public class BrowserActivity extends Activity {
@Override
public final void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);

WebView browser = (WebView) findViewById(R.id.webView);

browser.setHapticFeedbackEnabled(true);
browser.getSettings().setJavaScriptEnabled(true);
browser.getSettings().setSavePassword(false);

browser.getSettings().setDatabaseEnabled(true);
browser.getSettings().setDomStorageEnabled(true);
browser.getSettings().setDatabasePath("/data/data/" + browser.getContext().getPackageName() + "/databases/");

browser.loadUrl("http://my.app.com:10099");
}
}

list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="RestrictedBrowser"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="16"/>
<application android:label="@string/app_name">
<activity android:name="RestrictedBrowser.BrowserActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
</manifest>

错误

WARN/System.err(3961): android.database.sqlite.SQLiteConstraintException: column packagename is not unique (code 19) 07-12 13:57:43.425: WARN/System.err(3961): at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method) 07-12 13:57:43.425: WARN/System.err(3961): at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:857) WARN/System.err(3961): at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754) WARN/System.err(3961): at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64) WARN/System.err(3961): at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1665) WARN/System.err(3961): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594) ERROR/SQLiteLog(28735): (14) cannot open file at line 30241 of [00bb9c9ce4] 07-12 13:57:47.005: ERROR/SQLiteLog(28735): (14) os_unix.c:30241: (2) open(/NotificationPermissions.db) - 07-12 DEBUG/WebKit(28735): SQLite database failed to load from /NotificationPermissions.db Cause - unable to open database file 07-12 13:57:47.005: DEBUG/WebKit(28735): [ 28735:28758 D/WebKit ] external/webkit/Source/WebCore/platform/sql/SQLiteDatabase.cpp(71) : bool WebCore::SQLiteDatabase::open(const WTF::String&, bool)

最佳答案

您必须先创建数据库目录才能使用它。

使用下面的代码

String databasePath = browser.getContext().getDir("databases", 
Context.MODE_PRIVATE).getPath();
browser.getSettings().setDatabasePath(databasePath);

关于Android WebView 本地存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17615526/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com