安装Android System WebView

时间:2017-03-26 11:01:37

标签: android sqlite cordova android-webview android-sqlite

有一个传统的cordova应用程序存储"数据"在浏览器本地存储中。 这个应用程序的新版本是一个本机应用程序,试图访问这个"数据"通过访问本地存储数据库。

实现此目的的代码片段是: -

private void tryToGetHistory()
    {
        final WebView browser = (WebView) findViewById(R.id.browser);
    /* JavaScript must be enabled if you want it to work, obviously */

        browser.getSettings().setDomStorageEnabled(true);
        browser.getSettings().setDatabaseEnabled(true);

        ContextWrapper contextWrapper = new ContextWrapper(this);
        // Find the data directory
        File dataDir = new File(contextWrapper.getFilesDir().getParent());
        // Get the localStorage file
        File appWebViewFilesDir = new File(dataDir, "app_webview/Local Storage/file__0.localstorage");

        String TAG = "%Databases%";
        // Make sure it exists...
        if (appWebViewFilesDir.exists())
        {

            SQLiteDatabase database = null;
            Cursor cursor = null;
            boolean success = false;
            try
            {
                // Open the sqlite database
                database = SQLiteDatabase.openDatabase(appWebViewFilesDir.getPath(), null, SQLiteDatabase.OPEN_READONLY);

                // Get all the values in the item table, obviously you can query specific values if you want
                cursor = database.rawQuery("SELECT value FROM ItemTable", new String[]{});
                cursor.moveToFirst();
                while (!cursor.isAfterLast())
                {
                    // Our items are blobs
                    byte[] itemByteArray = cursor.getBlob(0);

                    // Decode the UTF-16 blob into a nice Java string...
                    String itemString = new String(itemByteArray, Charset.forName("UTF-16LE"));

                    // Just dump the values to the log
                    Log.d(TAG, "Item Value: " + itemString);
                    cursor.moveToNext();
                }
            } catch (IOError ex)
            {
                Log.e(TAG, "IO Error on getting data from previous version", ex);
            } catch (SQLiteException ex)
            {
                Log.e(TAG, "SQLite Exception", ex);
            } catch (Exception ex)
            {
                Log.e(TAG, "Exception", ex);
            } finally
            {
                // Safely close out our database..
                if (cursor != null)
                {
                    cursor.close();
                }
                if (database != null)
                {
                    database.close();
                }
            }
        }
    }

之前我有Android System WebView版本39,这段代码运行正常。 最近我将我的Android系统WebView更新到版本56.0.2924.87,然后上面的代码片段停止工作。

我现在收到以下错误: -

  

03-26 12:43:42.369 8691-8691 / com.schneider.zelionfctimer E / SQLiteLog:   (1)near"(&#34 ;:语法错误03-26 12:43:42.369   8691-8691 / com.schneider.zelionfctimer E / SQLiteLog:(11)数据库   [b3bb660af9] 03-26 12:43:42.369第100646行的腐败现象   8691-8691 / com.schneider.zelionfctimer E / SQLiteLog:(11)格式错误   数据库模式(MmapStatus) - 接近"(&#34 ;:语法错误03-26   12:43:42.370 8691-8691 / com.schneider.zelionfctimer E /%Databases%:   SQLite Execption                                                                           android.database.sqlite.SQLiteDatabaseCorruptException:格式错误   数据库模式(MmapStatus) - 接近"(&#34 ;:语法错误(代码11):,   编译时:SELECT值FROM ItemTable                                                                               在   android.database.sqlite.SQLiteConnection.nativePrepareStatement(母语   方法)                                                                               在   android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)                                                                               在   android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)                                                                               在   android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)                                                                               在android.database.sqlite.SQLiteProgram。(SQLiteProgram.java:58)                                                                               在android.database.sqlite.SQLiteQuery。(SQLiteQuery.java:37)                                                                               在   android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)                                                                               在   android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)                                                                               在   android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1255)                                                                               在MainActivity.tryToGetHistory(MainActivity.java:79)                                                                               在MainActivity.access $ 000(MainActivity.java:20)                                                                               在MainActivity $ 1.onClick(MainActivity.java:37)                                                                               在android.view.View.performClick(View.java:4780)                                                                               在android.view.View $ PerformClick.run(View.java:19866)                                                                               在android.os.Handler.handleCallback(Handler.java:739)                                                                               在android.os.Handler.dispatchMessage(Handler.java:95)                                                                               在android.os.Looper.loop(Looper.java:135)                                                                               在android.app.ActivityThread.main(ActivityThread.java:5254)                                                                               at java.lang.reflect.Method.invoke(Native Method)                                                                               在java.lang.reflect.Method.invoke(Method.java:372)                                                                               在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)                                                                               在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

您能否建议我如何编辑上面的代码段,以便我的应用可以支持此webview更新? 我的目标是能够提取存储在浏览器本地存储中的数据。我知道浏览器本地存储中的数据存储在SQLiteDatabase中。 请帮帮我,这对我来说非常重要。 提前谢谢,

1 个答案:

答案 0 :(得分:1)

  

SQLiteDatabaseCorruptException:格式错误的数据库架构(MmapStatus) - 接近"(&#34 ;:语法错误

这意味着SQLite库无法读取数据库文件。数据库文件实际上已损坏,或者该Web视图使用的SQLite库版本比您当前使用的版本更新。 检查是否可以使用latest version of sqlite3 from the tools package打开数据库文件。