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
New Developer
Posts: 26
Registered: ‎03-06-2012
My Device: playbook
My Carrier: 8298611647
Accepted Solution

blackberry.io.dir.appDirs not working

[ Edited ]

I'm trying to put the blackberry.io.dir.appDirs results into a DIV or through an alert() function, but javascript just stops working. Here is an example.

 

$(function(){
$('#core').html( blackberry.io.dir.appDirs );


        /* or  

alert( blackberry.io.dir.appDirs );

*/
});

New Developer
Posts: 26
Registered: ‎03-06-2012
My Device: playbook
My Carrier: 8298611647

Re: blackberry.io.dir.appDirs not working

[ Edited ]

Here is my config.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
        xmlns:rim="http://www.blackberry.com/ns/widgets"
        version="1.0.0.0">  
    <name> app </name>
    <author> me </author>
    <description> my app</description>
    <icon src="images/icon.png"/>
    <content src="http://10.0.0.8/app/index.html"/>
	<access uri="*" subdomains="true" />
    <rim:permissions>  
        <rim:permit>read_geolocation</rim:permit>
		<rim:permit>access_shared</rim:permit>
    </rim:permissions>    
	<feature id="blackberry.io.file" required="true"/>
	<feature id="blackberry.io.dir" required="true"/>
	<feature id="blackberry.app"/>
</widget>

 

 

Anithing wrong?

Contributor
Posts: 12
Registered: ‎07-07-2012
My Device: 9860
My Carrier: Rogers

Re: blackberry.io.dir.appDirs not working

Hi,

 

did you ever manage to get this working? I'm having the same issue now.

 

Thanks,

 

Raj

Highlighted
Retired
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: blackberry.io.dir.appDirs not working

I think its the nature of the type of object that is returned by appDirs. I'm curious if it doesn't respect the 'toString' method.

 

Try this instead (declare the appDirs object as its own variable, then use it to reference each path you want):

 

var d = blackberry.io.dir.appDirs;

//Application storage folder path:
alert(d.app.storage.path);

//Music path:
alert(d.shared.music.path);

//Camera path:
alert(d.shared.camera.path);

 

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Contributor
Posts: 12
Registered: ‎07-07-2012
My Device: 9860
My Carrier: Rogers

Re: blackberry.io.dir.appDirs not working

Hi Adam,

 

I tried changing my code the way you suggested but I'm still unable to read any local file. 

 

I'm attaching my code snippet below.

 

function readFile(fileName)
{
try{
var appDirs = blackberry.io.dir.appDirs;
var filePath = appDirs.shared.documents.path + '/' + fileName;
return filePath;
//blackberry.io.file.readFile(filePath,handleOpenedFile);
}
catch(e)
{
alert("error in readFile: " + e.name + " " + e.message);
}

 

The error i'm getting is "ReferenceError: Can't find variable: blackberry". My config.xml has all the necessary items as well. See below

 

  <rim:permissions>
    <rim:permit>access_shared</rim:permit>
  </rim:permissions>

  <access subdomains="true" uri="file:///accounts/">
    <feature id="blackberry.app.event" required="true"/>
    <feature id="blackberry.app" required="true"/>
    <feature id="blackberry.system.event" required="true"/>
    <feature id="blackberry.invoke"/>
    <feature id="blackberry.io.file" required="true"/>
    <feature id="blackberry.io.dir" required="true"/>
    <feature id="blackberry.ui.dialog"/>
  </access>

 What's weird about this is that the application works fine in the emulator and if I output the filepath as an alert, the ripple emulator seems to putput a correct path "file:///accounts/1000/appdata/emulatedapp/shared/documents/<filename>.xml" but the same alert returns "undefined" when launched from an actual playbook.

 

Raj

 

Retired
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: blackberry.io.dir.appDirs not working

It feels like its a coding bug.  The fact that you get "can't find variable blackberry" indicates that something hasn't been loaded properly.  At which point in your page load does the readFile method get called - after onload?

 

Actually - looking at your config.xml file, I think the issue has to do with the fact that your <feature> elements are being defined under the <access> element.  This would allow any *.html file that is read from the file system to interact with WebWorks APIs.

 

However if you have a local index.html page that is trying to access the blackberry.* objects, it would not find this object because it hasn't been whitelisted in this scope.  To fix this, you can simply do the following

 

  <rim:permissions>
    <rim:permit>access_shared</rim:permit>
  </rim:permissions>

  <!-- Allow local *.html pages to access these APIs -->
  <feature id="blackberry.io.file" required="true"/>
  <feature id="blackberry.io.dir" required="true"/>

  <access subdomains="true" uri="file:///accounts/">
    <feature id="blackberry.app.event" required="true"/>
    <feature id="blackberry.app" required="true"/>
    <feature id="blackberry.system.event" required="true"/>
    <feature id="blackberry.invoke"/>
    <feature id="blackberry.io.file" required="true"/>
    <feature id="blackberry.io.dir" required="true"/>
    <feature id="blackberry.ui.dialog"/>
  </access>

 

As a final suggestion, you can check out the kitchenSink sample application

https://github.com/blackberry/WebWorks-Samples/tree/master/kitchenSink

 

This sample has a working demo of using the blackberry.io.dir and the blackberry.io.file APIs:

http://blackberry.github.com/WebWorks-Samples/kitchenSink/html/apis/dir.html

http://blackberry.github.com/WebWorks-Samples/kitchenSink/html/apis/file.html

 

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Contributor
Posts: 12
Registered: ‎07-07-2012
My Device: 9860
My Carrier: Rogers

Re: blackberry.io.dir.appDirs not working

Hi Adam,

 

Thanks for that input. I managed to get it working based on your second suggestion. It was the missing <feature> element as they were being defined inside the <access> element. Once I moved them out, i was able to get it to work perfectly. Thanks for the help.

 

Cheers,

 

Raj