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

BlackBerry® World™ Development

Reply
Highlighted
New Developer
Posts: 15
Registered: ‎08-21-2009
My Device: Not Specified
Accepted Solution

Distribute data file along with cod file?

Hello all,

 

My app runs from a database file on the device's flash memory.  While the app can download data from my server to populate the database, the first download is fairly big and takes a while to run (I'm working on that).

 

It occurred to me that an alternative might be to supply a pre-populated database file along with the app, so that then the app will run straight out of the box without requiring that first sync.

 

Does anyone know if the App World store supports this - distribution of data as well as the app?

 

Many Thanks...

Developer
Posts: 343
Registered: ‎02-23-2009
My Device: 8700 | 8310 | BOLD | STORM

Re: Distribute data file along with cod file?

Just put an text or xml file or any file format of your choice in your resources and just read it and add to the database file on the devices flash memory upon start up.  This data is required upon startup, right?

New Developer
Posts: 15
Registered: ‎08-21-2009
My Device: Not Specified

Re: Distribute data file along with cod file?

Yes technically that would work for me, but probably not in practice.  I don't believe there is a way of deleting resources, so after extracting the data file to a read/write location I would then be left with a redundant copy of the file.  The database file is a few MB in size so I'd rather not have this amount of space wasted on the device.  Shame as I think your idea is quite clever.

 

Developer
Posts: 343
Registered: ‎02-23-2009
My Device: 8700 | 8310 | BOLD | STORM

Re: Distribute data file along with cod file?

[ Edited ]

You are correct about the wasted space.  But how about you still include a resource file but make it so that if your program needs to read the "core" data, read from the resource file and if it is new data, read from the DB.  I'm not sure what your application is doing so I don't know if this is feasible or not but if it is, this would solve your problem.  What do you think?

 

Resource or Database

Message Edited by RLord321 on 09-15-2009 09:56 AM
New Developer
Posts: 15
Registered: ‎08-21-2009
My Device: Not Specified

Re: Distribute data file along with cod file?

I think that's probably the best way it can be done - nice diagram! Smiley Happy

 

Any of my data records could potentially change with a future sync with the server, though most of them probably won't.  I'll set this as the solution though as I think it'll be helpful for others.

 

I'm going to see whether I can section off a portion of the database as core/read-only data, then this approach will work really well.

 

Thanks!

 

Contributor
Posts: 31
Registered: ‎04-30-2010
My Device: Curve 8900
My Carrier: ATT

Re: Distribute data file along with cod file?

I've got pretty much the same scenario going on.  Am I to understand from this dialog that it isn't possible to write to a file that was deployed as a /res in the COD?

New Developer
Posts: 15
Registered: ‎08-21-2009
My Device: Not Specified

Re: Distribute data file along with cod file?

As far as I know, resource files inside the COD are read only.  I ended up packaging a zipped data file inside the COD, then on first run of the app I unzip it to a read/write location (either the device store or the SD card).  From then on the app just works on the read/write copy.

 

New Contributor
Posts: 7
Registered: ‎09-14-2010
My Device: Not Specified

Re: Distribute data file along with cod file?

How ddid you get access to a file inside the .codFile??? I want to change my iconimage but I can´t get the imege file, it's in a folder inside my cod. --- Images/logo.png...

 

 

New Developer
Posts: 15
Registered: ‎08-21-2009
My Device: Not Specified

Re: Distribute data file along with cod file?

See:

http://www.blackberry.com/developers/docs/5.0.0api/java/lang/Class.html#getResourceAsStream(java.lang.String)

 

I use it like this, where MyFile.zip is in the same package as MyClass.java:

 

InputStream is = MyClass.class.getResourceAsStream("MyFile.zip");
if (is != null) {
  // Read from stream and close it
}
New Contributor
Posts: 7
Registered: ‎09-14-2010
My Device: Not Specified

Re: Distribute data file along with cod file?

Ok, thanks for your anwer, it was so fast... (and sorry for my english). In my case i'm working with widgets because in the company we can´t use java. Do you know how to get an url inside the .cod The method i'm using is

 

blackberry.app.setHomeScreenIcon(

"Images/Logo.png", false);

 

and I get an exception: The resource could not be retrieved because it was not foun in the config.xml, it ask me to put <access> element in my xml but I don't know how because it has to be using a protocol so, <access url="/Images"></access> sends an error when i'm compiling...