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

Java Development

Reply
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Resource Installer to SD Card - Application Sample

I have had occasion to include larger files and other resources like mp3s, images and videos, in an application.  If I include these as resources, I could have a 200 KB application and megabytes of data for that application.  I really don't need these in the application cod file and often they would be better stored on the SD Card - in fact some, like primed SQL databases, must be located on the SD Card.  So what to do?

 

And if I include these in the application, and then copy them to the SD Card, the resources are still taking up Application Space too. 

 

I could "side-load" these resources on to the SD Card, for example, by automatically downloading the files from a web site when the application starts, or providing the user with some instructions to download the files into the appropriate directory while their BB is USB connected.  But downloading using code on the BlackBerry typically has problems with communication and of course, it is more code to write.  Side loading onto the SD Card via the USB connection or other mechanisms, tends to be manual and error prone - even testers, who should understand the technical requirements, botch this up. 

 

So I'm trying a slightly different approach.

 

I'm adding these resources to a separate application.  This separate application is downloaded like any other application (perhaps even with the using application).  When it runs, it just copies the resources onto the SD Card, and then deletes itself.  And so far (though it is early days) this seems to work OK.  It makes updating easy and it takes up no application space!

 

So I thought I would create a sample application that does this, and make this available.  I'm hoping other people would find this useful and/or might be able to provide some feedback or suggestions for improvement. 

 

If you are interested, attached you will find a zip file containing an application in source form.  Please download and unzip the zip file, retaining the directory structure.  You will find a sample installer application, with JDE workspace and project files. I believe I have commented the code well enough so that you can read it and try it without further instructions.  If you don't understand it, please read it again, and review the API's that it uses.  I don't think there is anything tricky in here, though of course I could probably have written things a simpler way.  . 

 

The sample just copies a small text file from the resources in the application onto a specified directory on the SD Card. 

 

I am confident that you will be able to extend this to do whatever installation steps you want it to take - for example delete a previous version of an application (not necessarily this one), or even install an application from a resource file.  At this stage, I'm just using it to load resources onto the SD Card, but you can do whatever you like. 

 

Code is given as is, where is, with no warranty that it is fit for purpose and that it won't trash your BB, though of course, if you find something that looks like a bug, let me know via this Thread.  This code should run in any OS that is 4.2 or later. 

 

Assuming this works for you, please use this freely, without reference to me, there is no copyright, no obligations at all. 

 

I just hope it is useful. 

Please use plain text.
Trusted Contributor
Thecr0w
Posts: 178
Registered: ‎02-20-2011
My Device: 8700
My Carrier: at&t

Re: Resource Installer to SD Card - Application Sample

Great !dea

# I tried to change the world, but I couldn't find the source code #



Please use plain text.
Contributor
lakmalvbj
Posts: 18
Registered: ‎10-31-2011
My Device: 8900
My Carrier: BAS

Re: Resource Installer to SD Card - Application Sample

[ Edited ]

This is a brilliant idea. I have two questions

1. How can I package this with my app and run before my actual app install

2. Is there anyway to loop through files in the res folder?

 

Janaka

Please use plain text.
Developer
simon_hain
Posts: 16,001
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Resource Installer to SD Card - Application Sample

nice idea. why don't you make it a KB article?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Resource Installer to SD Card - Application Sample

@lakmalvbj

 

1.  You can't package it.  You can however get your app to check if the resources are present tell the user if the installer has not been run, and maybe (I've not done this, but I can't see why you can't, run the 'installer' if it is around

 

2.  There is not facility to loop through files, you have to know which ones are there.    But see later...

 

@Simon,

 

Was going to but no one seemed particularly interested 

 

In fact I have an enhancement I would like to publish, which allows people to add a ZIP file as the a resource, and then automatically unzip the zip file and write all the files to the SD Card.  I need to get authority to release this code, and of course, if no one is interested, why bother?  So let me know if you think this would be a good thing and I shall ask.

Please use plain text.
Contributor
lakmalvbj
Posts: 18
Registered: ‎10-31-2011
My Device: 8900
My Carrier: BAS

Re: Resource Installer to SD Card - Application Sample

Hi Peter,

 

Thank you for the reply.

 

I can't think of a reason why this installer is not going to useful for others. So please do a KB artical as Simon suggested. If you improve the code with zip file , my 2nd question would be answered. So looking forward to it..

 

 

Janaka

Please use plain text.
Developer
madiha
Posts: 107
Registered: ‎05-26-2011
My Device: Torch
My Carrier: Mobilink

Re: Resource Installer to SD Card - Application Sample

Good work !

tHANKS

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Resource Installer to SD Card - Application Sample

Please use plain text.