来自电话簿的J2ME联系人并且无法在诺基亚E5和E72中阅读

时间:2013-02-18 10:48:46

标签: java-me nokia pim

我的j2me应用程序具有与手机和SIM卡中的联系人进行消息传递的功能。我在诺基亚N70 M和诺基亚C2-02上测试了应用程序并运行良好。但是没有从诺基亚E5和E72获取联系人。如果我错了,请告诉我错误的可能性,在这里给你代码......

public void loadContacts()
{

    System.out.println("into show contacts1");
    try
    { 
    javax.microedition.pim.ContactList addressbook=null;
    javax.microedition.pim.ContactList simaddressbook=null;
    PIM pim = PIM.getInstance();
    System.out.println("into show contacts2");
    String[] allContactLists = PIM.getInstance().listPIMLists(PIM.CONTACT_LIST);
    System.out.println("into show contacts3");
    for(int ctr=0;ctr<allContactLists.length;ctr++)
    {
    pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY,allContactLists[ctr]);
    addressbook=(javax.microedition.pim.ContactList)(pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY));
    Contact contact = null;
        Enumeration items = null;
        items = addressbook.items();
        while (items.hasMoreElements()) {
            contact = (Contact) items.nextElement();
            int telCount = contact.countValues(Contact.TEL);
            int nameCount = contact.countValues(Contact.FORMATTED_NAME);
            if (telCount > 0 && nameCount > 0) {
                String contactName = contact.getString(Contact.FORMATTED_NAME, 0);
                    for (int i = 0; i < telCount; i++) {
                          String phoneNumber = contact.getString(Contact.TEL, i);
                         ContactFetcher contactfetcher=new ContactFetcher();
                          contactfetcher.setFotmattedName(contactName);
                          contactfetcher.settelName(phoneNumber);
                          PersistableManager pm=PersistableManager.getInstance();
                          pm.save(contactfetcher);
            }
            }
        }
    }
    if(!nokiaos)
    {
      simaddressbook=(javax.microedition.pim.ContactList)(PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE,"SIM"));
     Contact contact = null;
     Enumeration simitems=null;
     simitems=simaddressbook.items();
     while (simitems.hasMoreElements()) {
             System.out.println("into show contacts9");
            contact = (Contact) simitems.nextElement();
            int telCount = contact.countValues(Contact.TEL);
            int nameCount = contact.countValues(Contact.FORMATTED_NAME);
            if (telCount > 0 && nameCount > 0) {
                String contactName = contact.getString(Contact.FORMATTED_NAME, 0);
                    for (int i = 0; i < telCount; i++) {
                          String phoneNumber = contact.getString(Contact.TEL, i);
                          ContactFetcher contactfetcher=new ContactFetcher();
                          contactfetcher.setFotmattedName(contactName);

                          contactfetcher.settelName(phoneNumber);
                          PersistableManager pm=PersistableManager.getInstance();
                          pm.save(contactfetcher);
          }
        }
     }

    }


  }

              catch(Exception e)
              {
                  e.printStackTrace();
              }

}

这里我正在检测手机是s60还是s40,如果是s6o然后只读取s60中的pim触点,还是s40中的sim联系人。在此先感谢... :)

1 个答案:

答案 0 :(得分:2)

我终于解决了,我错过了存储联系人的命名约定之王。代码如下: - 哪个也在诺基亚E5和E72上运行。

  public void loadContacts()
  {

    System.out.println("into show contacts1");
   try
    { 
    javax.microedition.pim.ContactList addressbook=null;
    javax.microedition.pim.ContactList simaddressbook=null;
    PIM pim = PIM.getInstance();
    System.out.println("into show contacts2");
    String[] allContactLists = PIM.getInstance().listPIMLists(PIM.CONTACT_LIST);
    System.out.println("into show contacts3");

    pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY,allContactLists[0]);
    addressbook=(javax.microedition.pim.ContactList)(pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY));
    Contact contact = null;
        Enumeration items = null;
        items = addressbook.items();
        if(addressbook.isSupportedField(Contact.FORMATTED_NAME) && addressbook.isSupportedField(Contact.TEL))
        {
             while (items.hasMoreElements()) {
             System.out.println("into show contacts9");
            contact= (Contact) items.nextElement();
            int telCount = contact.countValues(Contact.TEL);
            int nameCount = contact.countValues(Contact.FORMATTED_NAME);
            if (telCount > 0 && nameCount > 0) {
                String contactName = contact.getString(Contact.FORMATTED_NAME, 0);
                    for (int i = 0; i < telCount; i++) {
                          String phoneNumber = contact.getString(Contact.TEL, i);

                         ContactPerson.addElement(contactName);    
                         Telephone.addElement(phoneNumber);
                         Imagedata.addElement("");

                     }
                }
             }
        }
        else
        {
            while (items.hasMoreElements()) {
            contact = (Contact) items.nextElement();
            String contactName="";
            contactName = contactName+contact.getStringArray(Contact.NAME,
               Contact.ATTR_NONE)[Contact.NAME_FAMILY];

            if(contactName.equals("null"))
            {
                contactName = contact.getStringArray(Contact.NAME,
                        Contact.ATTR_NONE)[Contact.NAME_GIVEN];
            }
            String phoneNumber=contact.getString(Contact.TEL, Contact.ATTR_NONE);
             if (contactName!=null && phoneNumber!=null) 
             {           
                         ContactPerson.addElement(contactName);    
                         Telephone.addElement(phoneNumber);
                         Imagedata.addElement("");

             }
            }
        }


  if(!nokiaos)
    {
      simaddressbook=(javax.microedition.pim.ContactList)(PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE,"SIM"));
     Contact contactsim = null;
     Enumeration simitems=null;
     simitems=simaddressbook.items();
     if(simaddressbook.isSupportedField(Contact.FORMATTED_NAME) && simaddressbook.isSupportedField(Contact.TEL))
     {
         while (simitems.hasMoreElements()) {
             System.out.println("into show contacts9");
            contactsim= (Contact) simitems.nextElement();
            int telCount = contactsim.countValues(Contact.TEL);
            int nameCount = contactsim.countValues(Contact.FORMATTED_NAME);
            if (telCount > 0 && nameCount > 0) {
                String contactName = contactsim.getString(Contact.FORMATTED_NAME, 0);
                    for (int i = 0; i < telCount; i++) {
                          String phoneNumber = contactsim.getString(Contact.TEL, i);
                         ContactPerson.addElement(contactName);    
                         Telephone.addElement(phoneNumber);
                         Imagedata.addElement("simico.png");


                    }
             }
        }
     }
     else
     {
         while (simitems.hasMoreElements()) {
             System.out.println("into show contacts9");
            contactsim= (Contact) simitems.nextElement();
            String contactName = contactsim.getStringArray(Contact.NAME,
               Contact.ATTR_NONE)[Contact.NAME_GIVEN];

            String phoneNumber=contactsim.getString(Contact.TEL, Contact.ATTR_NONE);
             if (contactName != null && phoneNumber!=null) 
             {
                         ContactPerson.addElement(contactName);    
                         Telephone.addElement(phoneNumber);
                         Imagedata.addElement("simico.png");

             }
          }
        }
     }

 }

              catch(Exception e)
              {
                  e.printStackTrace();
              }
   try
   {
                        ContactFetcher contactfetcher=new ContactFetcher(); 
                         contactfetcher.setFotmattedName(ContactPerson);
                         contactfetcher.settelName(Telephone);
                         contactfetcher.setImage(Imagedata);
                         PersistableManager pm=PersistableManager.getInstance();
                         pm.save(contactfetcher); 
   }
   catch(Exception ex)
   {

   }
}