Can sqlite databae be used with as3 air app for an

2019-09-13 02:18发布

问题:

My App and Sqlite connection works on simulator but does not work when publishes on android device.

Below are the sample codes, I have tried, all work on simulator but not on android phone

 // 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 ");}

And lastly, I suggest all as3 air developer to move on to native android if possible.

回答1:

to use sqlite in android try add in manifest file:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>