我在 Android 上安装了一个可以访问 SQL 数据库的 PhoneGap 应用程序。如果我卸载应用程序然后尝试重新安装它,我会收到一个安全错误,提示我无法访问数据库文件。如果我通过 App/Settings 删除此数据库文件,那么我可以重新安装该应用程序并且它工作正常。
我想在卸载应用程序时自动删除数据库,以便我(或其他用户)无需进入设置即可重新安装。
关于如何做到这一点的任何想法?
这是发生错误时的 LogCat 数据,我省略了一些我认为与此问题无关的内容,希望我没有遗漏任何内容:
11-27 18:10:52.859: I/dalvikvm(32482): Could not find method android.webkit.WebView.<init>, referenced from method org.apache.cordova.CordovaWebView.<init>
11-27 18:10:52.859: W/dalvikvm(32482): VFY: unable to resolve direct method 3200: Landroid/webkit/WebView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;IZ)V
11-27 18:10:52.859: D/dalvikvm(32482): VFY: replacing opcode 0x70 at 0x0001
11-27 18:10:52.859: D/dalvikvm(32482): VFY: dead code 0x0004-005b in Lorg/apache/cordova/CordovaWebView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;IZ)V
11-27 18:10:52.898: I/CordovaLog(32482): Changing log level to DEBUG(3)
11-27 18:10:52.898: I/CordovaLog(32482): Found preference for useBrowserHistory=true
11-27 18:10:52.898: D/CordovaLog(32482): Found preference for useBrowserHistory=true
11-27 18:10:52.898: I/CordovaLog(32482): Found preference for exit-on-suspend=false
11-27 18:10:52.898: D/CordovaLog(32482): Found preference for exit-on-suspend=false
11-27 18:10:52.898: D/JsMessageQueue(32482): Set native->JS mode to 2
11-27 18:10:52.906: D/DroidGap(32482): DroidGap.init()
11-27 18:10:52.906: D/CordovaWebView(32482): >>> loadUrl(file:///android_asset/www/index.html)
11-27 18:10:52.906: D/PluginManager(32482): init()
11-27 18:10:52.914: D/CordovaWebView(32482): >>> loadUrlNow()
11-27 18:10:52.914: D/DroidGap(32482): Resuming the App
11-27 18:10:52.921: D/SoftKeyboardDetect(32482): Ignore this event
11-27 18:10:52.953: D/DroidGap(32482): onMessage(onPageStarted,file:///android_asset/www/index.html)
11-27 18:10:52.953: D/SoftKeyboardDetect(32482): Ignore this event
11-27 18:10:52.960: I/gralloc(520): Allocated 0x660072 size 6488161
11-27 18:10:52.992: D/SoftKeyboardDetect(32482): Ignore this event
11-27 18:10:53.015: D/szipinf(32482): Initializing inflate state
11-27 18:10:53.015: D/szipinf(32482): Initializing zlib to inflate
11-27 18:10:53.023: D/szipinf(32482): Initializing inflate state
11-27 18:10:53.023: D/szipinf(32482): Initializing zlib to inflate
11-27 18:10:53.039: D/szipinf(32482): Initializing inflate state
11-27 18:10:53.039: D/szipinf(32482): Initializing inflate state
11-27 18:10:53.039: D/szipinf(32482): Initializing zlib to inflate
11-27 18:10:53.039: D/szipinf(32482): Initializing zlib to inflate
11-27 18:10:53.164: I/ActivityManager(520): Displayed com.example.ezbrzy_homework_planner/.EzBrzy_Main: +407ms
11-27 18:10:53.398: D/dalvikvm(520): GC_CONCURRENT freed 1451K, 27% free 12851K/17543K, external 9751K/11799K, paused 3ms+8ms
11-27 18:10:54.054: D/Cordova(32482): onPageFinished(file:///android_asset/www/index.html)
11-27 18:10:54.054: D/DroidGap(32482): onMessage(onNativeReady,null)
11-27 18:10:54.054: D/DroidGap(32482): onMessage(onPageFinished,file:///android_asset/www/index.html)
11-27 18:10:54.070: I/Database(32482): sqlite returned: error code = 14, msg = cannot open file at source line 25467
11-27 18:10:54.085: D/DroidGap(32482): onMessage(networkconnection,wifi)
11-27 18:10:54.093: D/DroidGap(32482): onMessage(spinner,stop)
11-27 18:10:54.093: I/gralloc(520): Allocated 0x660072 size 6488161
11-27 18:10:54.234: I/Database(32482): sqlite returned: error code = 23, msg = not authorized
11-27 18:10:54.304: D/dalvikvm(32482): GC_EXTERNAL_ALLOC freed 595K, 44% free 3534K/6279K, external 2755K/2773K, paused 30ms
11-27 18:10:54.328: I/gralloc(520): Allocated 0x660072 size 6488161
11-27 18:10:55.539: I/gralloc(520): Allocated 0x660072 size 6488161
11-27 18:10:56.062: D/DroidGap(32482): onMessage(spinner,stop)
11-27 18:10:57.164: I/Database(32482): sqlite returned: error code = 1, msg = no such table: assignments
11-27 18:10:57.218: I/gralloc(520): Allocated 0x660072 size 6488161
11-27 18:10:58.414: I/gralloc(520): Allocated 0x660072 size 6488161
如果我只是将数据库名称更改为其他名称,它就可以正常工作。现在我什至无法清除设备上的应用程序数据并让旧名称再次运行(在 droid razr 上)......
我猜你正在使用 SQLite 我曾经使用过它,但是我在将我的应用程序移植到 ios 时遇到了问题,然后我使用了 Phonegap 提供的非常易于使用的这种数据库:
http://docs.phonegap.com/en/2.2.0/cordova_storage_storage.md.html#Storage
您可以使用以下查询删除数据库:
db = window.openDatabase("TSSE", "1.0", "TSSE_DB", 200000);
db.transaction(populateDB, errorCB, successCB);
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DB_name');
tx.executeSql('CREATE TABLE IF NOT EXISTS DB_name (id, name, password, money)');
}