03-06-2012 07:41 PM - edited 03-06-2012 07:46 PM
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 );
*/
});
Solved! Go to Solution.
03-07-2012 10:17 PM - edited 03-07-2012 10:21 PM
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?
07-12-2012 08:08 PM
Hi,
did you ever manage to get this working? I'm having the same issue now.
Thanks,
Raj
07-16-2012 08:37 AM
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);
07-16-2012 11:41 AM
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,handleOpene dFile);
}
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/
Raj
07-16-2012 02:51 PM
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/tre
This sample has a working demo of using the blackberry.io.dir and the blackberry.io.file APIs:
http://blackberry.github.com/WebWorks-Samples/kitc
http://blackberry.github.com/WebWorks-Samples/kitc
07-17-2012 10:02 AM
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