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
lemieuxbedard
Posts: 6
Registered: ‎03-19-2013
My Carrier: Rogers
Accepted Solution

How can i access to my app file... Blackberry Playbook os

Situation:

My app webwork works properly at the exception of one thing. I have a button that supposed to open a pdf that is buddled with the app. let's say its in the root directory and its named test.pdf. My idea was to locate the position of the file (find the app path). Then use invoke function to launch adobe reader to open the file.

 

ex: path-to-my-app/test.pdf

 

I came across this: 

 

blackberry.io.dir.app.storage.path + "test.pdf"

 

blackberry.invoke.invoke({
target: "com.rim.bb.app.adobeReader",
action: "bb.action.OPEN",
type: "application/pdf",
uri: dir.app.storage.path + "test.pdf"
}, onSuccess, onError);

 

It seems that the invoke way doesn't work for BB playbook os.

 

Can someone help me about this?

 

Thanks a lot!

 

 

Please use plain text.
Developer
peardox
Posts: 1,227
Registered: ‎03-20-2011
My Carrier: 3, Orange, Vodafone

Re: How can i access to my app file... Blackberry Playbook os

I'm assuming you're put your PDF in your App directory. I don't think it's possible to access is from there via an external program

 

There's an old KB article - BlackBerry PlayBook File System Layout  that goes into it...

 

Basically you've got three really important directories an app uses (with a VERY long pathname before these...)

 

app - Your app lives here

data - Private storage for your app

shared - Shared storage for all apps

 

It appears that the folder app is, to all intents and purposes, read-only

 

Data is somewhere App can store files for it's own private use - however - you can't seem to be able to use this space directly from your app - by which I mean stick an image in there and display it with a <img .... /> tag. Its mass storage for files your app reads and writes

 

Shared is a free-for-all area. Connect to a PC and you can transfer files to / from it, your app can directly show images etc from this area as well.

 

The data dir also includes several other directoriesfor things like localStorage, database, downloads and suchlike

 

As far as I know (I'd love to be proved wrong on this) the only way to do something along the lines you want is to include it in your App, load it via AJAX then save it out into Shared - do that and your PDF invokation should work as it'll read the file from Shared where it's allowed

 

I know for a fact that you can read in files in your App's directory via AJAX (just been doing it for an ePub reader). Once you've got the data you can store it somewhere else (done that too)

 

I know, it's a very round-about way of doing things - it's called security :smileyhappy:

 

 

 

 




Click the like button if you find my posts useful!
Please use plain text.
Developer
peardox
Posts: 1,227
Registered: ‎03-20-2011
My Carrier: 3, Orange, Vodafone

Re: How can i access to my app file... Blackberry Playbook os

[ Edited ]

Forgot to mention...

 

Compile your app with the -g switch (debugging)

 

Get the IP address of your PlayBook (WiFi or USB)

 

Start app on PB

 

Open Google Chrome

 

Go to <PlayBookIPAddress>:1337

 

One BlackBerry Debugger at your beck and call!

 

Select your app from the menu - 2nd down usually

 

Give it a few seconds to get it's stuff sorted then press <F5> - this causes your app to reload with the debugger seeing everything that goes on - it's usually a good idea to do this as you might miss something that happens on startup otherwise

 

Now try opening your PDF - when the expected nothing happens you'll may see a red alert symbol in the lower right of Chrome - Press <Esc> and it'll tell you what went wrong (prob file permission error)

 

Not sure you'll get an error report as the error will likely come from the PDF reader - but you never know (not tried)

 




Click the like button if you find my posts useful!
Please use plain text.
New Contributor
lemieuxbedard
Posts: 6
Registered: ‎03-19-2013
My Carrier: Rogers

Re: How can i access to my app file... Blackberry Playbook os

Thanks for the help... I came across that solution recently but i cant make it work:
http://jsfiddle.net/J26m2/

The error come from: window.requestFileSystem the error is SECURITY_ERR

Maybe something i have to activate for the playbook?
Please use plain text.
Developer
peardox
Posts: 1,227
Registered: ‎03-20-2011
My Carrier: 3, Orange, Vodafone

Re: How can i access to my app file... Blackberry Playbook os

I had the same problem with PB + HTML5 FileSystem

 

I don't have anything to hand that uses shared but these are the doc pages that get near solving it

 

https://developer.blackberry.com/html5/apis/blackberry.io.dir.html

 

You're after something like ...

 

var dirs = blackberry.io.dir.appDirs;
var doc = dirs.shared.documents.path;

 

You've now got the shared documents directory in doc

 

Next check out

 

https://developer.blackberry.com/html5/apis/blackberry.io.file.html

 

You're after blackberry.io.file.readFile and blackberry.io.file.saveFile- there's an example which helps a lot (but is still confusing)

 

You' finally need the Utils stuff (https://developer.blackberry.com/html5/apis/blackberry.utils.html)

 

Now for the gotcha...

 

You're gonna have to read in the PDF via AJAX somehow - it'll either work or it won't

 

I'd try reading in as text, apply a btoa() to that then try saving it out to shared using the BASE64 encoding setting

 

IF (it's a BIG IF) that works you should be able to check it from a desktop to make sure it got thru unscathed

 

I've done Server -> data dir

Data Dir -> display in App (Base64 encoded images / dox)

App Dir -> use in App (ePub parsing)

 

Not tried App Dir binary file -> somewhere else yet - soz




Click the like button if you find my posts useful!
Please use plain text.
Developer
peardox
Posts: 1,227
Registered: ‎03-20-2011
My Carrier: 3, Orange, Vodafone

Re: How can i access to my app file... Blackberry Playbook os

Oops - obvious work-around

 

Base64 encode the PDF on the desktop before deploying it

 

Now when you read in via AJAX it's just a very long string of characters so AJAX will be more than happy with it

 

Definitely do-able




Click the like button if you find my posts useful!
Please use plain text.
New Contributor
lemieuxbedard
Posts: 6
Registered: ‎03-19-2013
My Carrier: Rogers

Re: How can i access to my app file... Blackberry Playbook os

The build over the air with the inspector enabled worked. I'm trying all the tip and tips you provided. I'll keep you posted :smileyhappy:
Please use plain text.
New Contributor
lemieuxbedard
Posts: 6
Registered: ‎03-19-2013
My Carrier: Rogers

Re: How can i access to my app file... Blackberry Playbook os

[ Edited ]

At the moment it seems that i am at almost 5% of completing this:

I'm using exactly this exemple the last post (Re: stringToblog save image problem):

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/stringToblog-save-image-problem/...

 

It seems that the file it save when i'm looking with:

blackberry.io.dir.listFiles(blackberry.io.dir.appDirs.shared.documents.path)

 

The application adobe or doc is lauching but it says that the file is corrupted... Here is my code:

http://jsfiddle.net/eUt65/1/

 

For this test i used the .doc file but my final file will be a .pdf

 

Thanks for the help again :smileyvery-happy:

 

 

Please use plain text.
Developer
peardox
Posts: 1,227
Registered: ‎03-20-2011
My Carrier: 3, Orange, Vodafone

Re: How can i access to my app file... Blackberry Playbook os

Where's base64ArrayBuffer coming from - assuming you've got a btoa somewhere handling that then

 

stringToBlob(encoded, "binary")

 

stringToBlob(encoded, "BASE64")

 

I reckon test.doc should be pre-encoded - one less thing to do / failure point




Click the like button if you find my posts useful!
Please use plain text.
New Contributor
lemieuxbedard
Posts: 6
Registered: ‎03-19-2013
My Carrier: Rogers

Re: How can i access to my app file... Blackberry Playbook os

problem solved :

I patched the action script code:

 

public function stringToBlob(data&colon;String, encoding:String):Object
{
           var characterSet:String = translateEncodingIntoASCharacterSet(encoding);
            var ba:ByteArray = new ByteArray();
            if (characterSet == "base64")
            {
                var base64Encoder:Base64Encoder = new Base64Encoder();
                base64Encoder.encode(data);
                ba.writeUTFBytes(base64Encoder.toString());
            }
	    else if (characterSet == "binary")
	    {
		var base64Decoder:Base64Decoder = new Base64Decoder();
                base64Decoder.decode(data);
                ba = base64Decoder.toByteArray();
	    }
            else
            {
                ba.writeMultiByte(data, characterSet);
            }

            var bm:BlobManager = getBlobManager();
            var blobId:String = bm.createBlob(ba).id;

            return new WebWorksReturnValue(blobId).jsonObject;
        }




http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/stringToblog-save-image-problem/...

Thanks for all peardox!!!!!!!!!
Please use plain text.