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
New Developer
Smolof
Posts: 11
Registered: ‎02-01-2013
My Device: Z10
Accepted Solution

Invoke Email with Attachment

Hi Guys ,

 

im trying to invoke the email-app with a predefined attachment.
 I read that u have to parse data in JSON-Format to the InvokationRequest, but im not sure how to do this exactly.

 

Here is what i have so far

 

InvokeManager invokeManager;
InvokeRequest request;

request.setTarget("sys.pim.uib.email.hybridcomposer");
request.setAction("bb.action.COMPOSE");
request.setMimeType("message/rfc822");

QVariantMap mail;

mail.insert("to", QUrl("test@test.com"));
				
request.setMetadata(mail);
				
InvokeTargetReply *reply = invokeManager.invoke(request);

 As far as i know, this should add the test@test.com adress to the mailto-field, but well it doesnt.

 

Does anybody know what im doing wrong or whats missing.

 

Thx

Smolof

 

Please use plain text.
New Developer
Smolof
Posts: 11
Registered: ‎02-01-2013
My Device: Z10

Re: Invoke Email with Attachment

Hey Guys,

 

it's me again. Still haven't found out anything.

 

Maybe there is a whole other approach i didn't consider yet.

 

So what i basically want to do, is add an existing file to an email-invoker.

 

Does anybody have any ideas?

 

Thx and Best Regards

Smolof

 

 

Please use plain text.
Developer
Ebscer
Posts: 875
Registered: ‎08-31-2009
My Device: 9530, 9630, 9800, 8530, 9900, 9810, 9930, PlayBook, Dev Alpha

Re: Invoke Email with Attachment

The following code works for me...

 

attachedObjects:
[
   Invocation
   {
        id: invoke
        query: InvokeQuery
        {
            id: q
            invokeActionId: "bb.action.SHARE"
            mimeType: "*"
            invokeTargetId: "sys.pim.uib.email.hybridcomposer"
        }
        onArmed:
        {
            trigger("bb.action.SHARE")
        }
    }
]

function shareFiles(s)
{
    q.uri = "file://"+s
    q.updateQuery()
}

 Where the argument s is a reference to the location of the file that you wish to attach...


Read my thoughts on BlackBerry Development at news.ebscer.com
Please use plain text.
New Developer
Smolof
Posts: 11
Registered: ‎02-01-2013
My Device: Z10

Re: Invoke Email with Attachment

Hey,

 

first of all thanks for ur reply.

 

But i dont want to just share a file, i want to open the Email-Composer with an adress and an attached file.

Maybe even with a predefined subject and body. 

 

 

 

 

 

Please use plain text.
BlackBerry Development Advisor
shaque
Posts: 236
Registered: ‎07-14-2008
My Device: Not Specified

Re: Invoke Email with Attachment

Please use plain text.
New Developer
Smolof
Posts: 11
Registered: ‎02-01-2013
My Device: Z10

Re: Invoke Email with Attachment

 

I would love to do that, but honestly i have no idea how.

I thought filling a QVariantMap and sending it as MetaData to the InvokeRequest would do the trick.

 

Would you be able to give me an example on how to send Data to the request in JSON-Format.

 

Thx in advance and best regards

Smolof

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: Invoke Email with Attachment

I've now tried using these approaches from QML, and also jumped down to the raw navigator_invoke_invocation_xxx() calls, to bypass any intermediate issues that may exist there.

 

I'm getting nothing different from what anyone else has reported in this or other threads on this.

 

I've tried setting up JSON data with navigator_invoke_invocation_set_metadata() and it's having no effect.

 

I can use the URI approach to prepopulate the fields, but then there's no apparent way to attach a file.

 

I can do the basic file SHARE approach, but then there's no way to prepopulate the fields.

 

If someone has anything they would like me to try, I'm all set up to explore here... but fresh out of ideas.

 

I have a question regarding the JSON approach... it shows a "from" field. Is that mandatory? I've tried leaving it out, tried setting it to the value actually shown (1234) since it's ambiguous whether that particular value is meaningful, and I've tried using several account values from my device. Nothing changes the fact that all the metadata appears to be ignored.


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!
Please use plain text.
BlackBerry Development Advisor
shaque
Posts: 236
Registered: ‎07-14-2008
My Device: Not Specified

Re: Invoke Email with Attachment

Sorry for the delay. Here is how I got this working this morning.

void InvokeEmail::sendEmail() {
	InvokeRequest request;
	request.setAction("bb.action.COMPOSE");
	request.setMimeType("message/rfc822");
	QVariantMap data;
	data["to"] = (QVariantList() << "you@gmail.com");
	data["subject"] = "This is a subject";

	data["body"] = "Hello there, things are great!";
	QString logpath = "/accounts/1000/shared/documents/test.pdf";
	QString logpathEncoded = QString(QUrl(logpath).toEncoded());
	qDebug() << "## LOG PATH: " + logpathEncoded;
	data["attachment"] = (QVariantList() << logpathEncoded);
	QVariantMap moreData;
	moreData["data"] = data;
	bool ok;
	request.setData(bb::PpsObject::encode(moreData, &ok));

	m_invokeManager->invoke(request);
}

 

 

Please use plain text.
Contributor
raysonyeung
Posts: 21
Registered: ‎02-07-2013
My Device: Z10

Re: Invoke Email with Attachment

This is really a solution of the topic.
Please use plain text.
New Contributor
xiuchundao
Posts: 8
Registered: ‎04-21-2013
My Device: Z10

Re: Invoke Email with Attachment

Hi, shaque, your code works well. While i want to invoke Text Message now.  i write the following code, but not work. What's wrong with my code? Thank you very much.:Helpsmilie:

void InvokeEmail::sendSMS() 
{
	InvokeRequest request;
	request.setTarget("sys.pim.text_messaging.composer");
	request.setAction("bb.action.COMPOSE" );
	request.setMimeType("application/text_messaging");

	QVariantMap data;

	data["to"] = 15850342922;
	data["body"] = "thank you";
	data["send"] = false;

	QVariantMap moreData;
	moreData["data"] = data;

	bool ok;

	request.setData(bb::PpsObject::encode(moreData, &ok));

	InvokeManager *invokeManager = new InvokeManager();
	invokeManager->invoke(request);
}

 

Please use plain text.