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

Web and WebWorks Development

Reply
New Contributor
Posts: 2
Registered: ‎06-24-2011
My Device: Curve 8520
My Carrier: Orange

Unable to access a file in device memory

Hi,

 

I'm developing my first WebWorks project using the Eclipse plug-in and I'm getting the following error when I try to access a file in device memory (using the simulator):

 

javax.microedition.io.ConnectionNotFoundException: Protocol not found: net.rim.device.cldc.io.local.Protocol

 

I came across the following code that shows how to access a file on the SD card so I imported the code into Eclipse and it works fine:

 

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/BlackBerry-WebWorks-Sample-Code-...

 

However, when I change the sample code to use device memory instead of the SD card it also encounters the same problem. The original code was:

 

var filePath = "file:///SDCard/myDataFile.txt";

var backupPath = "file:///SDCard/myDataFile2.txt";

 

I changed it to:

 

var filePath = "local:///myDataFile.txt";

var backupPath = "local:///myDataFile2.txt";

 

I've spent ages googling this problem but, so far, haven't managed to track down an answer. Any help would be much appreciated.  Apologies in advance if I'm doing something stupid!

 

Thanks.

 

Regular Contributor
Posts: 58
Registered: ‎01-19-2011
My Device: 9800
My Carrier: vodafone

Re: Unable to access a file in device memory

var filePath;

 

function

setFilePath() {

 

var root = blackberry.io.dir.getRootDirs();

filePath = root +'/MyFile.txt';

}

 

 

remember to add feature in cofig.xml.

 

blackberry.io.dir

blakberry.io.file

 

 

works for me

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Unable to access a file in device memory

The local:// protocol is for accessing files inside your application archive using AJAX or by linking to it in an anchor tag, image tag etc.

 

An example of accessing the in memory file system is:

 

file:///store/home/user/pictures/

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 2
Registered: ‎06-24-2011
My Device: Curve 8520
My Carrier: Orange

Re: Unable to access a file in device memory

Thanks Tim, I've got it working now. I added some code to, first of all, create my own directory in file:///store/home/user and now it's working fine.

 

Do BB Apps normally ask the user where they would like to store their data the first time the App is run? If not, should the default location be device memory or SD card? For example, I was thinking of storing the data in either of the following locations:

 

1) file:///store/home/user/MyCompanyName/MyProductName/subfolders... 

2) file:///SDCard/MyCompanyName/MyProductName/subfolders... 

 

Would that be following "good practice" in the BB App world?

 

Should I give the user the option of changing the location at a later date and automatically moving all of the existing folders / files for them?

 

Thanks again for your help.

 

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Unable to access a file in device memory

If it is small amounts of data you could likely get away with just storing it in the memory file system.. If you are going to be storing large amounts of data, or data that you would want to be removable then the SDCard is a definate option.

 

I don't think it would hurt to ask them where they would like to store their app data.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter