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

Java Development

Reply
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified
Accepted Solution

Creating VCard attachment

[ Edited ]

I need to programmatically send a contact as a VCard attachment via email.

 

Referring to the KB Article DB-00009 "How to - Create an Attachment" I have implemented this succcessfully on 4.2. However, the same code fails on 4.5 when the Message object is passed to the Messages application via Invoke().

 

The message displayed by the Email program is: "Email service does not support these types of attachments. Change the Send-Using field, or change the attachments".

 

I tried setting the following content types with no-joy:

 

"text/x-vcard" (the correct MIME type for this attachment)

 

BodyPart.ContentType.TYPE_ADDRESS_BOOK_STRING 

 

BodyPart.ContentType.TYPE_TEXT + bodyPart.ContentType.SUBTYPE_X_RIMDEVICE_ADDRESS_BOOK  

 

BodyPart.ContentType.TYPE_APPLICATION + BodyPart.ContentType.SUBTYPE_X_RIMDEVICE_ADDRESS_BOOK 

 

Has anyone else seen this issue?

 

Is there an updated version of the KB article somewhere that describes how this was changed for OS 4.5?

 

 

Message Edited by RexDoug on 10-03-2008 10:18 AM
Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Creating VCard attachment

Ooops...answered my own question.

 

See PDAPContactAttachmentPart

 

 

Please use plain text.
Developer
amrishodiq
Posts: 112
Registered: ‎09-23-2009
My Device: Not Specified

Re: Creating VCard attachment

Hi Rex,

I'm facing the same problem with your previous message. And I'm still having problem with this. Could you give me some snippet? 

 

Here is my code:

 

 

Multipart multipart = new Multipart();
		PDAPContactAttachmentPart vcard = new PDAPContactAttachmentPart(multipart);
		
		ContactList contacts = null;
		try {
			contacts = (ContactList) PIM.getInstance().openPIMList(
					PIM.CONTACT_LIST, PIM.READ_WRITE);
			Contact contact = contacts.createContact();
			String[] fieldName = new String[contacts.stringArraySize(Contact.NAME)];
			if (contacts.isSupportedField(Contact.FORMATTED_NAME)) 
				contact.addString(Contact.FORMATTED_NAME, PIMItem.ATTR_NONE, cont.getElement(MontroseContact.BUSINESS_NAME));
//			contact.addStringArray(Contact.NAME, PIMItem.ATTR_NONE, fieldName);
			if (contacts.isSupportedField(Contact.TEL)) 
				contact.addString(Contact.TEL, Contact.ATTR_WORK, cont.getElement(MontroseContact.PHONE_NUMBER));
			
			vcard.setContent(contact);
			String[] data_formats = PIM.getInstance().supportedSerialFormats(
		             PIM.CONTACT_LIST );
			ByteArrayOutputStream os = new ByteArrayOutputStream();
			PIM.getInstance().toSerialFormat( contact, os, "UTF-8", data_formats[ 0 ] );
			
			SupportedAttachmentPart attach = new SupportedAttachmentPart(multipart, "text/x-vcard", "contact.vcf", os.toByteArray());
			multipart.addBodyPart(attach);
			
			
			Store store = Session.getDefaultInstance().getStore();
            Folder[] folders = store.list(Folder.SENT);
            Folder sentfolder = folders[0];
			Message message = new Message(sentfolder);
			message.setContent(multipart);
			message.setSubject("Contact - "+cont.getElement(MontroseContact.BUSINESS_NAME));
			
			Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES,
					new MessageArguments(message));
		} catch (PIMException e) {
			throw new Exception(e.getMessage());
		}

 Thanks in advance.

 

Please use plain text.
Developer
amrishodiq
Posts: 112
Registered: ‎09-23-2009
My Device: Not Specified

Re: Creating VCard attachment

Hi Rex,

I'm facing the same problem with your previous message. And I'm still having problem with this. Could you give me some snippet? 

 

Here is my code:

 

 

Multipart multipart = new Multipart();
		PDAPContactAttachmentPart vcard = new PDAPContactAttachmentPart(multipart);
		
		ContactList contacts = null;
		try {
			contacts = (ContactList) PIM.getInstance().openPIMList(
					PIM.CONTACT_LIST, PIM.READ_WRITE);
			Contact contact = contacts.createContact();
			String[] fieldName = new String[contacts.stringArraySize(Contact.NAME)];
			if (contacts.isSupportedField(Contact.FORMATTED_NAME)) 
				contact.addString(Contact.FORMATTED_NAME, PIMItem.ATTR_NONE, cont.getElement(MontroseContact.BUSINESS_NAME));
//			contact.addStringArray(Contact.NAME, PIMItem.ATTR_NONE, fieldName);
			if (contacts.isSupportedField(Contact.TEL)) 
				contact.addString(Contact.TEL, Contact.ATTR_WORK, cont.getElement(MontroseContact.PHONE_NUMBER));
			
			vcard.setContent(contact);
			String[] data_formats = PIM.getInstance().supportedSerialFormats(
		             PIM.CONTACT_LIST );
			ByteArrayOutputStream os = new ByteArrayOutputStream();
			PIM.getInstance().toSerialFormat( contact, os, "UTF-8", data_formats[ 0 ] );
			
			SupportedAttachmentPart attach = new SupportedAttachmentPart(multipart, "text/x-vcard", "contact.vcf", os.toByteArray());
			multipart.addBodyPart(attach);
			
			
			Store store = Session.getDefaultInstance().getStore();
            Folder[] folders = store.list(Folder.SENT);
            Folder sentfolder = folders[0];
			Message message = new Message(sentfolder);
			message.setContent(multipart);
			message.setSubject("Contact - "+cont.getElement(MontroseContact.BUSINESS_NAME));
			
			Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES,
					new MessageArguments(message));
		} catch (PIMException e) {
			throw new Exception(e.getMessage());
		}

 Thanks in advance.

 

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Creating VCard attachment

Here is a snippet:

 

            multiPart = new Multipart();
            PDAPContactAttachmentPart vcard = new PDAPContactAttachmentPart(multiPart,contact);

            multiPart.addBodyPart(vcard);

Please use plain text.
Developer
amrishodiq
Posts: 112
Registered: ‎09-23-2009
My Device: Not Specified

Re: Creating VCard attachment

Hey, it works.

Thanks a lot.

Please use plain text.
Visitor
JW-POML
Posts: 1
Registered: ‎09-21-2010
My Device: BB Curve 9300
My Carrier: Bell Mobility

sending contact info to a different contact

I saw that you had figure out how to add a vcard by adding in the code. But I"m not a programmer so are there any blackberry apps that will do this? I want to take a contact from my address book and send it to an email address via email not text. How do we submit this request to RIM as it is something all Blackberry customers would use. Every day someone asks me for a number or an email address and I have to copy and paste it into emails as I don't have my whole database on messenger. Any thoughts would be appreciated. blessings, Jerilyn I have a BB Curve 9300 version 4.5.2
Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: sending contact info to a different contact

There is a product called REXconnect that does this. It is on App World, or you can go to www.rexwireless.com

 

 

 

 

Please use plain text.
Trusted Contributor
gopi
Posts: 126
Registered: ‎10-15-2010
My Device: Torch 9850
My Carrier: Not specified

Re: Creating VCard attachment

Hi RexDoug, I am tried to implement your above code in my app, it works well but when i am tested to open the attached vcard it is empty and click add to contacts from the sent folder no contacts are added. I am testing in my device Bold9900. Please help me to retify my mistake.

public void getVCard() {
		
		Multipart multipart = new Multipart();		
		Logger.logEventInfo("Begin Multipart ");
		ContactList contacts = null;
		try {  
			contacts = (ContactList) PIM.getInstance().openPIMList(
					PIM.CONTACT_LIST, PIM.READ_WRITE);
			Contact contact = contacts.createContact();
			Logger.logEventInfo("createContact");
			  
			if (contacts.isSupportedField(Contact.FORMATTED_NAME)) 
				contact.addString(Contact.FORMATTED_NAME, PIMItem.ATTR_NONE,"Blackberry");
			
			Logger.logEventInfo("Fromatted name Blackberry");
			if (contacts.isSupportedField(Contact.TEL)) 
				contact.addString(Contact.TEL, Contact.ATTR_WORK, ""+909412345);
			PDAPContactAttachmentPart vcard = new PDAPContactAttachmentPart(multipart,contact);
			vcard.setContent(contact);
			String[] data_formats = PIM.getInstance().supportedSerialFormats(
					PIM.CONTACT_LIST );
			ByteArrayOutputStream os = new ByteArrayOutputStream();
			PIM.getInstance().toSerialFormat( contact, os, "UTF-8", data_formats[ 0 ] );
			
			Logger.logEventInfo("Multipart attachment");
			//SupportedAttachmentPart attach = new SupportedAttachmentPart(multipart, "text/x-vcard", "contact1.vcf", os.toByteArray());
			multipart.addBodyPart(vcard);

			Logger.logEventInfo("Multipart");
			Store store = Session.getDefaultInstance().getStore();
			Folder[] folders = store.list(Folder.SENT);
			Folder sentfolder = folders[0];
			Message message = new Message(sentfolder);
			message.setContent(multipart);
			message.setSubject("Contact - 123");

			Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES,
					new MessageArguments(message));
		} catch (Exception e) {
			Logger.logEventInfo("Exception"+e.toString());

		}
	}

 9900.jpg      9900-01.jpg

 

In simulator, i tried to add to contacts, i got empty screen like above.

Please use plain text.
Trusted Contributor
gopi
Posts: 126
Registered: ‎10-15-2010
My Device: Torch 9850
My Carrier: Not specified

Re: Creating VCard attachment

Sorry for inconvience, myself fixed the issue, by refering the ContactLinkingDemo sample.

String[] name = new String[7];
            
            if (contacts.isSupportedArrayElement(Contact.NAME, Contact.NAME_FAMILY)){
                name[Contact.NAME_FAMILY] = FName;
                Logger.logEventInfo("name "+ name[Contact.NAME_FAMILY].toString());
            }
            if (contacts.isSupportedArrayElement(Contact.NAME, Contact.NAME_GIVEN)){
                name[Contact.NAME_GIVEN] = LName;
                contact.addStringArray(Contact.NAME, PIMItem.ATTR_NONE, name);
                Logger.logEventInfo("contacts3 "+ name[Contact.NAME_GIVEN].toString());
            }
            
                contact.addString(Contact.TEL, Contact.ATTR_MOBILE, MobileNo);
                Logger.logEventInfo("MobileNo "+ MobileNo);
            Multipart multipart = new Multipart();
		String[] data_formats = PIM.getInstance().supportedSerialFormats(
					PIM.CONTACT_LIST );
			ByteArrayOutputStream os = new ByteArrayOutputStream();
			PIM.getInstance().toSerialFormat( contact, os, "UTF-8", data_formats[ 0 ] );

			Logger.logEventInfo("Multipart attachment");
			SupportedAttachmentPart attach = new SupportedAttachmentPart(multipart, "text/x-vcard", "contact1.vcf", os.toByteArray());
			multipart.addBodyPart(attach);

 

 

Thank you Rex.

Please use plain text.