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

Native Development

Reply
Developer
Developer
Posts: 28
Registered: ‎02-10-2012
My Device: playbook 4G/LTE
My Carrier: none

using navigator_invoke() to view local file:// urls

not sure if i have a coding bug, or bumping into unsupported area.

 

can the navigator/ browser view file:// type files?

 

i'd like to include help documents with my Aapp in the form of .html documents

(just html4.0 -- no javascript, etc)

 

if it is supported, should the url path be relative to the app sandbox ?
 eg:  file://data/index.html

or absoulte to the sandobx, eg: file:///data/index.html

or relative to HOME, eg: file://index.html

or perhaps file://${HOME}/data/index.html

 

or perhaps have the App expand out the $HOME environment and place

it in there similar to

   file:////accounts/1000/appdata/net.dognose.APPNAME.testDev__APPNAMEeae63b00b/data/index.html

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: using navigator_invoke() to view local file:// urls

I wouldn't expect any app other than your own to have any access to your app's data area. The security of the system should prevent almost everything else from reading from it, including the system browser.

If you want to display HTML for your app, I believe you need to build in something that uses the standard browser component. Since this question was posted in the NDK forum, I fear the answer for now is "that's not possible" as I haven't seen any sign that the WebKit stuff is exposed to us here yet. (I would expect it to be available once the Qt stuff is fully ported, mind you, but I don't know if that's their strategy for this sort of thing.)

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Developer
Posts: 28
Registered: ‎02-10-2012
My Device: playbook 4G/LTE
My Carrier: none

Re: using navigator_invoke() to view local file:// urls

it is only my app that wants its own .html documentation.

 

i thought navigator_invoke() would be the ticket, pointing it at a file://  url under my $HOME

 

perhaps not. Smiley Sad

 

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: using navigator_invoke() to view local file:// urls

My point is that you would not be able to launch another app via that API and have it read data in your app's sandbox, as the other app would not have access to your app's data.

Also, checking https://bdsc.webapps.blackberry.com/native/reference/com.qnx.doc.bps.lib_ref/com.qnx.doc.bps.lib_ref... right now I see no indication that it supports the file: URI scheme anyway, so even if it had the necessary permissions to read your files I don't see anything suggesting that API would let you do it.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 142
Registered: ‎07-27-2011
My Device: Red Z10, 32GB PlayBook, Numerous Android/WP8/FirefoxOS/Other devices
My Carrier: T-Mobile

Re: using navigator_invoke() to view local file:// urls

[ Edited ]

You can view the Browser's sandboxed files by typing "local:" into the url bar, mayber the same URI would work for your app (bit late to the party here aren't I?).

-----------------------------------------------------------------------------------------



Retired
Posts: 54
Registered: ‎10-26-2011
My Device: Playbook
My Carrier: Rogers

Re: using navigator_invoke() to view local file:// urls

Might I suggest a much simpler solution?  Why not just publish your help files on a website and invoke the browser with the address of that website?

Developer
Developer
Posts: 28
Registered: ‎02-10-2012
My Device: playbook 4G/LTE
My Carrier: none

Re: using navigator_invoke() to view local file:// urls

well both website and local tablet publishing Smiley Happy

 

you see, not a lot of reliable internet connection on a sailboat in the ocean...

kinda funny how now days everyone just assumes internet connection -- and highspeed at that Smiley Happy

 

when i get the chance, i'll play with that local. uri scheme suggestion above, sounds intriguing.

unfortunately i'm off the app development at the moment.

 

thanks for the ideas to ya both!

 

BlackBerry Development Advisor
Posts: 683
Registered: ‎11-29-2011
My Device: PRIV
My Carrier: Rogers

Re: using navigator_invoke() to view local file:// urls

if you absolutely need to access the files from a browser, copy the files to

shared/misc/your_apps_shared_folder relative to your sandbox.

 

The files will be indexed by the media indexer, however if you make the directory "hidden" by naming it ".your_apps_shared_folder" instead, then it should be skipped over.  Alternately, I believe dropping a ".nomedia" file in the folder will cause the files to be ignored and not show up in eg. the picture viewer, etc.

 

Then you can point the browser to these files.

 

You would need to add access_shared to your bar-descriptor in order to write files to shared/

 

The downside of this approach is that you are leaving files behind on the device even after uninstall.  If the help files were not large, you could copy them only when the user needs help, and delete them each restart of your app or something.  I'd lean more towards the ".nomedia" solution, as this way, at least the user can see that the folder exists and they can clean it up later if they want to reclaim the storage space. 

 

Cheers,

Sean

Trusted Contributor
Posts: 117
Registered: ‎02-29-2012
My Device: PlayBook & Nexus 4

Re: using navigator_invoke() to view local file:// urls

[ Edited ]

Yes, you can. This is another important piece of information that IMHO should already be in the official documentation for WebWorks, but for some reason we are left to figure it out on our own. Some API functions are poorly documented. Anyway, here goes.

 

First, you need these in your config.xml file:

 

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

<feature id="blackberry.io.dir" />
<feature id="blackberry.io.file" />
<feature id="blackberry.utils" />
<feature id="blackberry.invoke" />
<feature id="blackberry.invoke.BrowserArguments" />

As others have already pointed out, the browser is an external application and it cannot access the files of your sandboxed app, therefore you need to either copy or create those files in the shared folder. Let "myfile.html" be the file you want to open in the browser. Here is how you can create it:

 

var filePath = blackberry.io.dir.appDirs.shared.documents.path + '/myfile.html';
if (blackberry.io.file.exists(filePath))
{
    blackberry.io.file.deleteFile(filePath);
}		
var htmlStr = "" + 
"<html>\n" +
"    <head>\n" +
"        <title>\n" +
"            myfile\n" +
"        </title>\n" + 
"        <meta encoding='utf-8' />\n" +	
"    </head>\n" +
"    <body>\n" +
"        test myfile\n" +
"    </body>\n" +
"<html>\n";	
var blob = blackberry.utils.stringToBlob(htmlStr);
blackberry.io.file.saveFile(filePath, blob);

 

To copy it from your app folder to the shared folder you need to read the content of the file into a string var and then save it to a new file in the shared folder. There is a post elsewhere that shows how to read local text files using XMLHttpRequest().

 

Finally, you can open the .html file by invoking the PB browser, like this:

 

var filePath = blackberry.io.dir.appDirs.shared.documents.path + '/myfile.html';
var APP_TYPE = "appType";
var INVOKE_API_URL = "blackberry/invoke";
var INVOKE_LOCATION = INVOKE_API_URL + "/invoke";
var uri = INVOKE_LOCATION;
var remote = new blackberry.transport.RemoteFunctionCall(uri);
remote.addParam(APP_TYPE, filePath);
remote.makeAsyncCall();

These last few lines can be simplified. Please note that I have not used this code in a while and I posted it without re-testing, hope nothing is missing and it works without changes.

Developer
Posts: 133
Registered: ‎03-28-2011
My Device: BlackBerry 9900 & PlayBook
My Carrier: Bell

Re: using navigator_invoke() to view local file:// urls

So I have a potential solution for you that I stumbled upon when trying to do some OAuth2 stuff, since I am in a similar predicament.

 

You can certainly host pages from within your own sandbox, but it's not the easiest thing to do.

 

Basically, you need to run a mini web server within your app, and have your app navigator_invoke to http://localhost:1234, where 1234 is some port of your choosing that's above 1024. If you decide to go down this route, PLEASE restrict access to the server, such that it only handles requests from localhost (i.e. the PlayBook/Dev Alpha).

 

https://github.com/kylefowler/twitter-bb10/blob/master/src/oauth/kqoauthmanager.cpp

 

In that particular file, you'll find some refernces to a server. It's creating it using QtNetworkManager. I haven't gone into much of the details, but that's a potential option that could work with Cascades/Qt on the Dev Alpha too.

 

Here's another example: http://doc.qt.nokia.com/solutions/4/qtservice/qtservice-example-server.html

 

Otherwise, if you don't want to have a Qt dependency, you'll need to find another library to use. Anyway, that's what's I'm using. Hope that helps. If so, like the post and/or mark it solved.


Founder of Pulsecode Inc. and taab
Authomator - Two-factor authentication codes on BlackBerry 10 - http://www.xitijpatel.com/ - Follow @xitijpatel
Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!