1

私の j2me アプリケーションには、電話や sim の連絡先とのメッセージング機能があります。アプリケーションをテストし、Nokia N70 M と Nokia C2-02 でも正常に動作しました。ただし、Nokia 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 であるかを検出しています。前もって感謝します...:)

4

1 に答える 1

2

連絡先が保存されている命名規則の王様が欠けていることを、ついに解決しました。コードは以下のようなものです:- Nokia 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)
   {

   }
}
于 2013-05-17T12:59:08.580 に答える