我的应用程序和Sqlite连接在模拟器上工作,但在android设备上发布时不工作。
下面是示例代码,我已经尝试过了,所有的工作在模拟器上,但不是在android手机
// SAMPLE-1
var conn:SQLConnection = new SQLConnection();
conn.addEventListener(SQLEvent.OPEN, openSuccess);
conn.addEventListener(SQLErrorEvent.ERROR, openFailure);
var fileLocation:File = File.applicationStorageDirectory.resolvePath("assets/weddingsql.sqlite"); ;
conn.openAsync(fileLocation, SQLMode.READ);
// SAMPLE-2
var fileLocation:File = File.applicationStorageDirectory.resolvePath("assets/weddingsql.sqlite"); ;
var storageDbFilePath:File = File.applicationStorageDirectory.resolvePath("weddingsql.sqlite");
fileLocation.copyToAsync(storageDbFilePath, true);
fileLocation.addEventListener(Event.COMPLETE, fileCopiedHandler);
function fileCopiedHandler(event:Event):void {
trace("File Copied....");
conn.openAsync(storageDbFilePath, SQLMode.READ);
}
// Used in both the samples
private function openSuccess(evt:SQLEvent):void{
trace(" can not make connection to Database "); }
private function openFailure(evt:SQLErrorEvent):void{
trace(" can not make connection to Database ");}
最后,如果可能的话,我建议所有的as3 air开发者都转向原生android。
在android中使用sqlite:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>