Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Acenet
Posts: 249
Registered: ‎11-02-2010
My Device: PlayBook
Accepted Solution

Application local data storage ?

[ Edited ]

Hello all.

  I would like to store data from within the application installed on the PlayBook.

Would anyone know where is this dedicated space and how to access it ?

The main usage would be to use a SQLite database (but not only).

(Is it possible with the simulator at all ?)

 

 

[Edit: the message is more specific]

 

JC
Please use plain text.
BlackBerry Development Advisor
jdolce
Posts: 172
Registered: ‎10-25-2010
My Device: Not Specified

Re: Application local data storage ?

The best place to store data for your application is in the application storage directory. You can access it with the following code.

 

 

var dbFile:File = File.applicationStorageDirectory.resolvePath( "my.db" );

 

 

If you want to bundle a database with your application and then have it writeable, you will need to copy it to this directory before writing to it. The reason being is your application directory is read-only. To access a file that was bundled in the root of your application, you could use the following. Then you could use the File copy methods to copy it to the applicaiton storage directory.

 

 

var bundledDb:File = File.applicationDirectory.resolvePath( "my.db" );

 

 

Hope that helps.

 

Julian

Please use plain text.
Developer
Acenet
Posts: 249
Registered: ‎11-02-2010
My Device: PlayBook

Re: Application local data storage ?

[ Edited ]

Hello Julian, thanks for the answer.

 

Actually I've tried to use ApplicationStorage already, but I got an Error 3003: "File or directory does not exist" exception.

When I run the app. in Flash Burrito's internal simulator, there is no error: the db file is properly found.

But it looks like File.applicationStorage is not found on the PlayBook Simulator.

 

Is there a simple test to check the correct path for the App Storage ?

 

 

[Edit 1]

Some news: I could check that the ApplicationStorageDirectory path is finally ok (properly created in the PlayBook Sim.)

The problem actually comes from the ApplicationDirectory, where I search for the "source" file to load into the dbFile.

 

So the command "File.applicationDirectory.resolvePath("assets/MyFile.ext");" return something like:

"/mlc/sandboxes/guest/PROJECTNAME.debug.XXXXXXXXXX/app/air/assets/MyFile.ext"

(the XXXXXXXXXX looks to be the serial ID of the deployed project)

And so this file "does not exist" when I access it.

(reminder: it works fine in the internal Flash simulator)

 

Is there a simple test to check the correct path for the deployed App. ?

(still searching...)

 

[Edit 2]

Well, it looks like the solution was related to the (non) embedded file when deploying.

So I included the file I need (an xml file) in the deploying command line, and it was found properly on the PlayBook, using ApplicationDirectory (as described by Julian).

 

Just to notice, I first tried to include the full "assets" directory, with a resulting error:

java.lang.IndexOutOfBoundsException
at java.io.ByteArrayOutputStream.write(Unknown Source)
at com.qnx.bbt.deploy.Deploy.readPackage(Deploy.java:173)
at com.qnx.bbt.deploy.Deploy.verifyPackageId(Deploy.java:138)
at com.qnx.bbt.deploy.Deploy.sendRequest(Deploy.java:124)
at com.qnx.bbt.deploy.Deploy.run(Deploy.java:100)
at com.qnx.bbt.deploy.Deploy.main(Deploy.java:73)
at com.qnx.bbt.airpackager.BarAirPackager.callLauncher(BarAirPackager.java:206)
at com.qnx.bbt.airpackager.BarAirPackager.run(BarAirPackager.java:129)
at com.qnx.bbt.airpackager.BarAirPackager.main(BarAirPackager.java:78)
Error: null

 (It may be related to a specific file inside assets....or to the size of the directory... but it's not a big deal)

 

 

 

So, finally resolved. The final word would be: don't forget to include the "assets" files you need ! :smileyhappy:

 

 

JC
Please use plain text.