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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Highlighted
New Contributor
Posts: 9
Registered: ‎09-27-2012
My Device: Curve 9220
My Carrier: Viettel

Webworks PhoneGap write file error (OS 7 + OS 6)

Hi,

 

I'm developing an Webworks PhoneGap application that needs to write text to .txt file for caching purpose. I got error code = 1 when tried to write text to .txt file(not on SD card). I'm using BlackBerry Curve 9220 OS 7. Here's my code:

 

// function write data to file, file name is specified url
var file_name = null;
var data_to_write = null;
function writeToFile(url, data){
	//alert('write');
	//alert(data);
	file_name = url.replace(/\//g, '').replace(/:/g,'');
	//alert(file_name);
	data_to_write = JSON.stringify(data);
	//alert(data_to_write);
	window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem, failWrite);
}

 function gotFileSystem(fileSystem){
	// alert(fileSystem);
	fileSystem.root.getFile(file_name, {create: true}, getFileToWriteSuccess, failWrite);
}

function getFileToWriteSuccess(fileEntry){
	
    //alert('fileEntry : '+fileEntry);
	fileEntry.createWriter(gotFileWriter, failWrite);
}

function gotFileWriter(writer){
	//alert(data_to_write);
	writer.write(data_to_write);
	//writer.close();
}

function failWrite(evt){
	alert(evt.target.error.code);
	$.mobile.loading('hide');
}

 Here's my config.xml:

 

<feature id="blackberry.system" required="true" version="1.0.0.0" />
  <feature id="org.apache.cordova" required="true" version="1.0.0" />
  <feature id="blackberry.find" required="true" version="1.0.0.0" />
  <feature id="blackberry.identity" required="true" version="1.0.0.0" />
  <feature id="blackberry.pim.Address" required="true" version="1.0.0.0" />
  <feature id="blackberry.pim.Contact" required="true" version="1.0.0.0" />
  <feature id="blackberry.app" required="true" version="1.0.0.0" />
  <feature id="blackberry.app.event" required="true" version="1.0.0.0" />
  <feature id="blackberry.system.event" required="true" version="1.0.0.0"/>
  <feature id="blackberry.widgetcache" required="true" version="1.0.0.0"/>
  <feature id="blackberry.media.camera" />
  <feature id="blackberry.ui.dialog" />
  <feature id="blackberry.media.microphone" required="true" version="1.0.0.0"/>
  <feature id="blackberry.invoke" />
  <feature id="blackberry.invoke.MessageArguments" />
  <feature id="blackberry.message" />
  <feature id="blackberry.message.sms" />
  <feature id="blackberry.system.event" version="1.0.0"/>
  <feature id="blackberry.push" required="true" version="1.0.0.0"/>
   <feature id="blackberry.io.file" required="true" version="1.0.0.0" />
	<feature id="blackberry.utils"   required="true" version="1.0.0.0" />
	<feature id="blackberry.io.dir"  required="true" version="1.0.0.0" />
	<rim:permissions>
		<rim:permit>access_shared</rim:permit>
	</rim:permissions>

  
  <!-- Cordova API -->
  <access subdomains="true" uri="file:///store/home" />
  <access subdomains="true" uri="file:///SDCard" />
...

P/S: My app runs well on BlackBerry Storm 9520 OS 5.

Please give advise. Thank in advance!

Retired
Posts: 165
Registered: ‎09-24-2012
My Device: Passport
My Carrier: Bell

Re: Webworks PhoneGap write file error (OS 7 + OS 6)

Hello thanhtrand,

 

In BBOS 6 and 7, we introduced WebKit, and therefore the syntax slightly differs. Please see the fixed code below:

	
function writeToFile(url, data){
	//alert('write');
	//alert(data);
	file_name = url.replace(/\//g, '').replace(/:/g,'');
	//alert(file_name);
	data_to_write = JSON.stringify(data);
	//alert(data_to_write);

        //add webkit before requestFileSystem and filesystem is now in window.PERSISTENT
	window.webkitRequestFileSystem(window.PERSISTENT, 0, gotFileSystem, failWrite);
}

function gotFileWriter(writer){
	//alert(data_to_write);

	console.log(data_to_write);

	//writer accepts a Blob, so we create one and pass in your string
        var blob = new Blob([data_to_write], {type: 'text/plain'});

	writer.write(blob);
	//writer.close();
}

 The rest of your code is correct, so implement the code above, test and report back.

New Contributor
Posts: 9
Registered: ‎09-27-2012
My Device: Curve 9220
My Carrier: Viettel

Re: Webworks PhoneGap write file error (OS 7 + OS 6)

[ Edited ]

Hi anzor_b,

 

Sorry for my late response. Thanks for your help but I've applied your code, the app still cannot write file successfully. Maybe I need more time for WebKit to use it. I'll give it a try soon.

 

Fortunately, my app worked properly after I had inserted SD card to device.

 

P/S: My app doesn't work while device is plugged into computer via cable. Unplug device and app works well.

 

Thanks again,

 

thanhtrand

Retired
Posts: 165
Registered: ‎09-24-2012
My Device: Passport
My Carrier: Bell

Re: Webworks PhoneGap write file error (OS 7 + OS 6)

Hi thanhtrand,

 

Glad to hear your applications works. When you plug the device into the computer, if you do not select "USB Mass Storage" or "USB Drive", the SD Card should be available to the application. Let me know if that works for you.

New Contributor
Posts: 9
Registered: ‎09-27-2012
My Device: Curve 9220
My Carrier: Viettel

Re: Webworks PhoneGap write file error (OS 7 + OS 6)

[ Edited ]

Hi anzor_b,

 

I've tried your code again but my app still doesn't work. Thank you anyway.

 

thanks,

 

P/S: I need to go ahead for completing other features of my app. I think I'll learn WebKit after finishing this app.

 

thanhtrand