Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

How to add a video clip to a contact in Java ME

From Wiki
Jump to: navigation, search
Article Metadata
Created: jarmlaht (21 Nov 2007)
Last edited: hamishwillee (26 Jul 2013)

This article explains how to add a video clip to a contact in Java ME. This feature is included in the Series 40 5th Ed. FP1 devices, which has firmware 5.xx or newer.



Many of the latest S60 and Series 40 devices support the feature of adding a video clip as contact's ringing tone. However, there is no such thing in PIM API (JSR-75), there is no VIDEO field in Contact class. So, adding a video clip to a contact has not been possible in Java ME. Now it has been made possible in some of the Series 40 5th Edition FP1 devices. This feature is included in the Series 40 5th Ed. FP1 devices, which has sw 5.xx or newer. You can check the software version you have by typing *#0000# in your phone.

Note: The integer value of the new video field equals to PIMItem.EXTENDED_FIELD_MIN_VALUE (= 16777216).

How to use the new video field:

  1. Make sure, that you have a video clip in your device and check the path and name to it for later use (see 4) below
  2. Create a ContactList: ContactList contacts = (ContactList) pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
  3. Create a Contact: Contact contact = contacts.createContact();
  4. Check, if this new field is supported and if it is, add the video to the contact by using Contact.addString() method:
    	if (contacts.isSupportedField(PIMItem.EXTENDED_FIELD_MIN_VALUE)) {

The full source code for a test MIDlet:

Source code:

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class VideoFieldMIDlet extends MIDlet {
private ContactForm form;
public void startApp() {
form = new ContactForm("VideoFieldMIDlet", this);
public void pauseApp() {
public void destroyApp(boolean unconditional) {

Source code:

import javax.microedition.lcdui.*;
import javax.microedition.pim.*;
public class ContactForm extends Form implements CommandListener {
private static final int VIDEO_URL = 16777216; // Equals to PIMItem.EXTENDED_FIELD_MIN_VALUE
private TextField firstnamefield;
private TextField lastnamefield;
private TextField numberfield;
private TextField videofield;
private Command addCommand;
private Command exitCommand;
private PIM pim;
private ContactList contacts = null;
private VideoFieldMIDlet midlet;
private String first_name;
private String last_name;
private String fullname;
private String number;
public ContactForm(String title, VideoFieldMIDlet midlet) {
this.midlet = midlet;
firstnamefield = new TextField("First name:", "", 30, TextField.ANY);
lastnamefield = new TextField("Last name:", "", 30, TextField.ANY);
numberfield = new TextField("Number:", "", 50, TextField.PHONENUMBER);
videofield = new TextField("Video file:", "", 100, TextField.ANY);
addCommand = new Command("Add contact", Command.SCREEN, 1);
exitCommand = new Command("Exit", Command.EXIT, 1);
private void writeContact() {
first_name = firstnamefield.getString();
last_name = lastnamefield.getString();
fullname = first_name + " " + last_name;
number = numberfield.getString();
pim = PIM.getInstance();
try {
contacts = (ContactList) pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
catch (PIMException pime) {
append("Opening PIM list: exp: " + pime);
catch (SecurityException se) { // the application is not allowed to access the list
append("Exp: " + se);
try {
Contact contact = contacts.createContact();
String[] name = new String[contacts.stringArraySize(Contact.NAME)];
String video = videofield.getString();
if (contacts.isSupportedArrayElement(Contact.NAME, Contact.NAME_FAMILY))
name[Contact.NAME_FAMILY] = last_name;
if (contacts.isSupportedArrayElement(Contact.NAME, Contact.NAME_GIVEN))
name[Contact.NAME_GIVEN] = first_name;
contact.addStringArray(Contact.NAME, PIMItem.ATTR_NONE, name);
if (contacts.isSupportedField(Contact.TEL))
contact.addString(Contact.TEL, Contact.ATTR_HOME, number);
// Use Contact.addString() method instead of Contact.addBinary() method for
// adding a video file to contact's video field, as shown below.
if (contacts.isSupportedField(VIDEO_URL) && checkVideoURL(video))
contact.addString(VIDEO_URL, PIMItem.ATTR_NONE, video);
// These lines would work too.
//contact.addString(PIMItem.EXTENDED_FIELD_MIN_VALUE, PIMItem.ATTR_NONE, video);
//contact.addString(16777216, PIMItem.ATTR_NONE, video);
else {
append("File doesn't exist!\n");
if (contacts.isSupportedField(Contact.UID))
append("Contact UID: " + contact.getString(Contact.UID, 0) + "\n");
catch (UnsupportedFieldException ufe) {
append("Exp: " + ufe);
catch (PIMException pime) {
append("commit(): exp: " + pime);
catch (IllegalArgumentException iae) {
append("Exp: " + iae);
append("Contact added.\n");
public boolean checkVideoURL(String url) {
// Checks if the video file exists.
boolean exists = false;
try {
FileConnection fconn = (FileConnection), Connector.READ);
if (fconn.exists()) exists = true;
catch (IOException ioe) {
System.out.println("IOException: " + ioe.getMessage());
return exists;
public void commandAction(Command c, Displayable d) {
if (c == addCommand) {
if (c == exitCommand) {

See also

This page was last modified on 26 July 2013, at 05:58.
52 page views in the last 30 days.