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
Trusted Contributor
basitj
Posts: 107
Registered: ‎04-08-2011
My Device: BlackBerry Q10
My Carrier: Mobilink
Accepted Solution

BB10 Webworks - Sending jpg from www folder

I'm trying to send an image using following code and it fails. Only thing I'm not sure about is URI part. I'm I correct in using blackberry.io.home to access www folder in my webworks app?

 

The jpg being sent is in www/img folder

 

Here's the code.

 

 

        function sendCardFB() {
          
            blackberry.invoke.invoke({
            target: "Facebook",
            action: "bb.action.SHARE",
            type: "image/jpeg",
            uri: "file://"+blackberry.io.home+"/img/wp"+theid+".jpg"
            }, onSuccess, onError);
        }

 

 

The code just calls onError in this case.

 

Get Speedometer on your phone. http://www.speedometer.mobi
Please use plain text.
Administrator
astanley
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: BB10 Webworks - Sending jpg from www folder

What parameter values are passed to your onError function?  See the errorHandler code sample on this page as a tip on how to capture this info correctly:

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

 

Our shareCard sample app demonstrates how to share an image:

https://github.com/blackberry/BB10-WebWorks-Samples/blob/master/shareCard/js/card.js

 

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: BB10 Webworks - Sending jpg from www folder

Instead of:
"file://"+blackberry.io.home+"/img/wp"+theid+".jpg"

Give this a shot:
"local:///img/wp"+theid+".jpg"

This should give you access to the resources packaged with your BAR file.

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Trusted Contributor
basitj
Posts: 107
Registered: ‎04-08-2011
My Device: BlackBerry Q10
My Carrier: Mobilink

Re: BB10 Webworks - Sending jpg from www folder

You rock Erik

 

I was over complicating things.

 

 

local:/// worked. No sandbox, no nothing :smileyhappy:

 

Cheers

 

 

Get Speedometer on your phone. http://www.speedometer.mobi
Please use plain text.
Trusted Contributor
basitj
Posts: 107
Registered: ‎04-08-2011
My Device: BlackBerry Q10
My Carrier: Mobilink

Re: BB10 Webworks - Sending jpg from www folder

Guys, now following code works great.

 

blackberry.invoke.invoke({
                target: "Facebook",
                action: "bb.action.SHARE",
                type: "image/jpeg",
                data: "local:///img/wp"+theid+".jpg"
            }, onSuccess, onError);

 

 

The file is in my www/img/  folder and I've sent it as a Facebook post.

 

Though I've not been able to send it to twitter using following code:

 

blackberry.invoke.invoke({
                target: "Twitter",
                action: "bb.action.SHARE",
                type: "image/jpeg",
                data: "local:///img/wp"+theid+".jpg"
            }, onSuccess, onError);   

 

Or sending email fails using following code:

 

blackberry.invoke.invoke({
                target: "sys.pim.uib.email.hybridcomposer",
                action: " bb.action.OPEN, bb.action.SENDEMAIL ",
                type: "image/jpeg",
                data: "local:///img/wp"+theid+".jpg"
            }, onSuccess, onError);

 

 

In both above cases (Twitter and Email), the card is launched but the attachment image is nowhere to be found.

 

Thoughts?

Get Speedometer on your phone. http://www.speedometer.mobi
Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: BB10 Webworks - Sending jpg from www folder

[ Edited ]

Hmm, will look at this today and will let you know what we find...

 

EDIT: All three invocations appear to be working just fine here.

 

I am testing with the following. The only differences are the target being invoked.

 

path = 'local:///img/image.png';

blackberry.invoke.invoke(
	{
		'target': 'Facebook',
		'action': 'bb.action.SHARE',
		'type': 'image/png',
		'uri': path
	},
	function onSuccess() {
		console.log('success');
	},
	function onError(error) {
		console.log(error);
	}
);
					
blackberry.invoke.invoke(
	{
		'target': 'Twitter',
		'action': 'bb.action.SHARE',
		'type': 'image/png',
		'uri': path
	},
	function onSuccess() {
		console.log('success');
	},
	function onError(error) {
		console.log(error);
	}
);
					
blackberry.invoke.invoke(
	{
		'target': 'sys.pim.uib.email.hybridcomposer',
		'action': 'bb.action.SHARE',
		'type': 'image/png',
		'uri': path
	},
	function onSuccess() {
		console.log('success');
	},
	function onError(error) {
		console.log(error);
	}
);

Each one invokes Facebook, Twitter, and the Email Composer with the image attached as expected. Note that the action for all three should be: 'bb.action.SHARE' which may explain the UIB failure.

 

Can you please confirm that you have an active Twitter and Email account configured on your device? Also, are you testing in the same application for all three? (i.e. does Facebook work and the others do not?) Or do you have separate projects? If separate, can you please just double-check that the image does indeed exist at that path?

 

You could try injecting an image into your Document when it loads just to confirm that the image path is infact valid. Example:

 

var img = document.createElement('img');
img.addEventListener('load', function () {
	document.body.appendChild(img);
}, false);
img.src=path;

 

Again I am relying on that path variable that i set to: "local:///img/image.png"

 

Which device model / OS version are you testing on? (Can you confirm the full OS version from Settings > About > OS?)

 


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Trusted Contributor
basitj
Posts: 107
Registered: ‎04-08-2011
My Device: BlackBerry Q10
My Carrier: Mobilink

Re: BB10 Webworks - Sending jpg from www folder

Works. Thanks ! :smileyhappy:

 

 

Yes I do have a working FB/Twitter/Email account on the device.

 

and Yes the app has all 3 share features.

 

 

Get Speedometer on your phone. http://www.speedometer.mobi
Please use plain text.
Trusted Contributor
basitj
Posts: 107
Registered: ‎04-08-2011
My Device: BlackBerry Q10
My Carrier: Mobilink

Re: BB10 Webworks - Sending jpg from www folder

 

And I keep asking for more Eric

 

Is there a way to add some default text to the email, facebook post and tweet in addition to the image?

 

BTW, thanks again, the image is going fine now.

 

 

Get Speedometer on your phone. http://www.speedometer.mobi
Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: BB10 Webworks - Sending jpg from www folder

[ Edited ]

Combining image and text sharing seems to be a little trickier. Let me check with the invocation experts and get back to you.

 

For Facebook and Twitter, this does not appear to be possible; this would need to be implemented in those applications directly and it does not look like this has been done yet. These feature requests have been brought up though.

 

For the Email Composer, it seems that this may be possible:

http://developer.blackberry.com/html5/documentation/email.html

 

See the section titled: Composing an email with prepopulated fields

 

I haven't been able to test this directly yet, however I believe that something along these lines should work:

 

	blackberry.invoke.invoke(
		{
			'target': 'sys.pim.uib.email.hybridcomposer',
			'action': 'bb.action.COMPOSE',
			'type': 'message/rfc822',
			'data': {
				'body': 'Hello World!',
				'attachment': [path]
			}
		},
		function onSuccess() {
			console.log('success');
		},
		function onError(error) {
			console.log(error);
		}
	);

 

I will confirm as soon as I am back at my dev PC. But again, it seems it should be possible for the Email Composer, but not for Twitter/Facebook invocation.

 

EDIT: 

 

After speaking with my colleages, the above should be working for the Email Composer, but in my testing is not. I'm going to log a bug with the development teams to get their eyes on this.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.