Showing posts with label J2ME. Show all posts
Showing posts with label J2ME. Show all posts

2010/06/24

Read Contacts using JSR75

This MIDlet reads the contact names and numbers from the Phonebook using JSR 75
 
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
 
public class   PIMMidelt extends MIDlet 
{
 ReadPIM readPim;
 Display display;
 
 public void startApp()
 {
  display = Display.getDisplay(this);
  readPim  = new ReadPIM(this);
  display.setCurrent(readPim);
 }
 public void pauseApp()
 {
 }
 public void destroyApp(boolean uc)
 {
 }
}
 
 
import javax.microedition.lcdui.*;
import javax.microedition.pim.*;
import java.util.*;
import java.io.*;
public class ReadPIM extends Form  implements Runnable,CommandListener
{
 PIM pim;
 PIMList pimlist;
 Contact contact=null;
 Enumeration enumeration;
 PIMMidelt midlet;
 
 String contactName="";
 String contactNo="";
 
 
 StringItem name;
 StringItem telno;
 Thread thread=null;
 Command exitCmd = new Command("Exit",Command.EXIT,1);
 
 public ReadPIM(PIMMidelt midlet)
 {
  super("Reading contacts");
  this.midlet = midlet;
 
  pim = PIM.getInstance();
 
  thread = new  Thread(this);
  thread.start();
  addCommand(exitCmd);
  setCommandListener(this);
 
 }
 
 public void run()
 {
  readContacts();
 }
 
 public void readContacts()
 {
  String[] lists = pim.listPIMLists(pim.CONTACT_LIST);
  for (int i = 0; i < lists.length; i++)
  {
  try{
  pimlist = pim.openPIMList(pim.CONTACT_LIST,pim.READ_WRITE);
  }catch(Exception e){}
 
 
  try{
  enumeration = pimlist.items();
  }catch(Exception e){}
 
  while (enumeration.hasMoreElements())
  {
   contact = (Contact)enumeration.nextElement();
 
   try{
   if(pimlist.isSupportedField(Contact.FORMATTED_NAME)&& 
                               (contact.countValues(Contact.FORMATTED_NAME) >0))
    {
     contactName += contact.getString(Contact.FORMATTED_NAME,0) 
                                                                   +"\r\n";;
     System.out.println("COntact name:"+contactName);
    }
  }catch( Exception e){}
 
  int phoneNos = contact.countValues(Contact.TEL);
  try{
   if(pimlist.isSupportedField(Contact.TEL) && 
                                           (contact.countValues(Contact.TEL) >0))
   contactNo += contact.getString(contact.TEL,0) +"\r\n";
    System.out.println("contact No  :"+contactNo);
   }catch( Exception e){}
 
  }
 
  name = new StringItem("Name",contactName);
  telno = new StringItem("No",contactNo);
  append(name);
  append(telno);
 
  }
 }
 
 public void commandAction(Command c , Displayable d)
 {
  if(c == exitCmd)
  {
   midlet.destroyApp(true);
   midlet.notifyDestroyed();
 
  }
 
 }
}

2010/06/14

How to get Phone IMEI number with J2ME


International Mobile Equipment Identity (IMEI) is used to identify valid devices connected to GSM and UMTS network. This number can be accessed from a mobile phone by dialing *#06# on the keypad. IMEI is commonly use by software developers as part of software protection scheme to prevent it from being pirated.
JavaME developers however suffers from a drawback because MIDP/CLDC specification does not include an API to obtain IMEI from mobile devices. However there are few phone manufacturers included this functionality through System.getPropery() calls.
Here's how to get IMEI number from mobile devices of different manufacturers

Nokia
JAVA:
  1. System.getProperty("phone.imei");
  2. System.getProperty("com.nokia.IMEI");
Note ; Requires signed midlet. S60 3rd edition device does not requires signing for this to work.
Sony-Ericsson
JAVA:
  1. System.getProperty("com.sonyericsson.imei");
Note ; might not work on all model, YMMV
Motorola
JAVA:
  1. System.getProperty("IMEI");
  2. System.getProperty("com.motorola.IMEI");

Samsung
JAVA:
  1. System.getProperty("com.samsung.imei");
Siemens
JAVA:
  1. System.getProperty("com.siemens.imei");
Hopefully this information can aid you in your J2ME programming projects.
Quick Tip :
It's quite hard to determine the phone model/manufacturer well ahead beforehand. For a more robust solution, I suggest that you combine the above call with System.getProperty("microedition.platform").