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

Adobe AIR Development

Reply
Contributor
Posts: 11
Registered: ‎03-01-2013
My Device: Simulator BB10
My Carrier: unknown, company employer

AIR email with json and attachments

[ Edited ]

Hey there (first post), 

 

I need some help invoking the native email-client with prepopulated fields and attachments via json.

As Described here:

 

http://developer.blackberry.com/cascades/documentation/device_platform/invocation/email.html

(btw, great "ANE"-to-os-pipeline, nice docs)

 

So far I managed to prepopulate:

- the message with a text using request.data

- several fields using "mailto:"

- attaching a file with request.uri

 

...but not everything together, i need some prepopulated fields and 2 attachments. 

I guess - because it involves several mimetypes - that only works with json (mimetype:message/rfc822). 

 

my sample code:

 

 

import qnx.invoke.InvokeAction;
import qnx.invoke.InvokeManager;
import qnx.invoke.InvokeRequest;		
		
protected function sendMailJson():void
{
	
	var request:InvokeRequest = new InvokeRequest();
	request.target = "sys.pim.uib.email.hybridcomposer";
	request.action = "bb.action.COMPOSE";
	request.mimeType = "message/rfc822";
	
	var jsonString:String = JSON.stringify(
		{
			to:"test@fest.de",
			subject:"Look at me",
			body:"Someone has to read this, fast"
		}
	);
	
	// VARIANT 1
	request.metadata = jsonString;
	
	// OR ???
	
	// VARIANT 2
	var jsonBytes:ByteArray = new ByteArray();
	jsonBytes.writeUTFBytes(jsonString);
	jsonBytes.position = 0;
	request.data = jsonBytes;
	
	// add eventlisteners...
	InvokeManager.invokeManager.invoke(request);
}

 

 

I tried both variants (before even adding attachment-files), none worked.

 

Questions: 

1) is the json 

request.metadata

OR 

request.data

 

2) which json params are required/optional.

 

3) why didnt it work... Smiley Happy

 

 

Thx a lot 

Dave

 

 

 

 

 

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: AIR email with json and attachments

Looking at:  http://developer.blackberry.com/air/documentation/bb10/email.html#ufa1355425510139

 

var jsonString:String = JSON.stringify(
		{
			to: ["test@fest.de" ],
			subject:"Look at me",
			body:"Someone has to read this, fast"
		}
	);

 Do a trace on the result of jsonString to verify it is good JSON.

var jsonBytes:ByteArray = new ByteArray();
jsonBytes.writeUTFBytes(jsonString);
request.data = jsonBytes;

 Should be correct.

 

Remove : request.mimeType = "message/rfc822"; since you are doing a direct invocation.

 

This should help.

Contributor
Posts: 11
Registered: ‎03-01-2013
My Device: Simulator BB10
My Carrier: unknown, company employer

Re: AIR email with json and attachments

 

 

Thank you for the fast reply, jtegen. 

 

I added the array brackets for "to" and tried again without mimetype. 

Traced jsonString: 

{"to":["test@fest.de"],"body":"Someone has to read this, fast","subject":"Look at me"}

 

No success.

 

I also tested again with changed mimetypes (none | "message/rfc822" | "text/plain"), didnt help either 

 

 

Since i dont have (yet, europe) a real device im using The VM running BB10Alpha 10.261 Simulator.

Did you actually test it on a device ?  (just to make sure its not just a sim-shortcoming)

 

Verdave

 

 

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: AIR email with json and attachments

Try asking on the Cascade forum the same question (or search first). Since we do not have one forum for invocation, you will need to ask the same generic question to all the development forums. Someone has probably done this.
Contributor
Posts: 11
Registered: ‎03-01-2013
My Device: Simulator BB10
My Carrier: unknown, company employer

Re: AIR email with json and attachments

[ Edited ]

 

Well, at least its not an ANE/AIR- specific bug (if it gets fixed in the APi, it will hopefully work in AIR without extra work).

Seems im not the only one having trouble with json-invoke.

 

http://supportforums.blackberry.com/t5/Cascades-Development/Invoke-Email-with-Attachment/m-p/2129331...

 

http://supportforums.blackberry.com/t5/Cascades-Development/Email-Composer-Not-Working/m-p/2166005/h...

 

 

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: AIR email with json and attachments

Well, at least you can do the mailto method. Does not help with attachments, but it is something.

If you have to send an attachment, you can try "share" the file the email app. That might work. User would have to fill in the to, subject and body.

We're suppose to get 10.1 this month. It might be fixed there.