无法访问/读取诺基亚中的 SIM 电话簿

发布于 2024-12-18 20:20:32 字数 2711 浏览 3 评论 0原文

我正在尝试访问诺基亚 5130c-2 XpressMusic 上的电话簿和 SIM 电话簿。 该应用程序运行时没有错误,但它只返回手机电话簿中的号码。当我使用此代码列出可用的电话簿时,

String[] all_contact_lists=PIM.getInstance().listPIMLists(PIM.CONTACT_LIST);

它会同时提供电话簿和 SIM 卡列表。 IE 1. 电话 2. SIM

我已尝试使用此代码显式读取 SIM 卡,但它仍然没有返回任何内容(即使我在 SIM 卡中保存了号码。) 代码:

ContactList clist = (ContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY,
                "SIM");

这是我的完整代码::

import javax.microedition.midlet.*;
import javax.microedition.pim.*;
import com.sun.lwuit.*;
import java.util.*;

public class contacts extends MIDlet
{
    private List my_list=new List();
    private String[] names=null;
    public void startApp()
    {
        Display.init(this);
       Form my_form=new Form("Contacts List");       
       String[] all_contact_lists=PIM.getInstance().listPIMLists(PIM.CONTACT_LIST);
       //Iterate through available phonebooks
       for(int db=0; db<all_contact_lists.length; db++)
       {
        try {
            ContactList clist = (ContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY,
                    all_contact_lists[db]);
            Enumeration contacts=clist.items();
            while(contacts.hasMoreElements())
            {
                Contact contact=(Contact)contacts.nextElement();
                try{
                    String phone_contact="";
                    names=contact.getStringArray(Contact.NAME, 0);
                    for(int i=0; i<names.length; i++)
                    {
                        if(names[i]!=null)
                            phone_contact+=" "+names[i];
                    }
                    //my_list.addItem(phone_contact);
                    int phone_numbers=contact.countValues(Contact.TEL);
                    if(phone_numbers>0)
                    {
                         String number=contact.getString(Contact.TEL,0);
                        my_list.addItem(phone_contact+":"+number);
                    }
                    else
                    {
                        my_list.addItem(phone_contact);
                    }
                    //clist.removeContact(contact);
                }
                catch (Throwable t) {
            t.printStackTrace();
            }

            }
        } catch (PIMException ex) {
            ex.printStackTrace();
        }
       }
       //my_list.addItem(all_contact_lists);
       my_list.setRenderingPrototype("WWWWWWWWWWWWWWWWWWWW");
       my_form.addComponent(my_list);
       my_form.show();
       }
    public void pauseApp(){}
    public void destroyApp(boolean unconditional){}


}

am trying to access both the Phone's phonebook and SIM phonenook on Nokia 5130c-2 XpressMusic.
The app runs without errors but it only returns the numbers from the phone's Phonebook. When I list the available phonebooks using this code

String[] all_contact_lists=PIM.getInstance().listPIMLists(PIM.CONTACT_LIST);

it gives me both the Phonebook and SIM card lists. i.e
1. Phone
2. SIM

I have tried explicitly reading from the SIM card using this code but it still returns nothing(even though I have numbers saved in the SIM card.)
Code:

ContactList clist = (ContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY,
                "SIM");

Here's my complete code::

import javax.microedition.midlet.*;
import javax.microedition.pim.*;
import com.sun.lwuit.*;
import java.util.*;

public class contacts extends MIDlet
{
    private List my_list=new List();
    private String[] names=null;
    public void startApp()
    {
        Display.init(this);
       Form my_form=new Form("Contacts List");       
       String[] all_contact_lists=PIM.getInstance().listPIMLists(PIM.CONTACT_LIST);
       //Iterate through available phonebooks
       for(int db=0; db<all_contact_lists.length; db++)
       {
        try {
            ContactList clist = (ContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY,
                    all_contact_lists[db]);
            Enumeration contacts=clist.items();
            while(contacts.hasMoreElements())
            {
                Contact contact=(Contact)contacts.nextElement();
                try{
                    String phone_contact="";
                    names=contact.getStringArray(Contact.NAME, 0);
                    for(int i=0; i<names.length; i++)
                    {
                        if(names[i]!=null)
                            phone_contact+=" "+names[i];
                    }
                    //my_list.addItem(phone_contact);
                    int phone_numbers=contact.countValues(Contact.TEL);
                    if(phone_numbers>0)
                    {
                         String number=contact.getString(Contact.TEL,0);
                        my_list.addItem(phone_contact+":"+number);
                    }
                    else
                    {
                        my_list.addItem(phone_contact);
                    }
                    //clist.removeContact(contact);
                }
                catch (Throwable t) {
            t.printStackTrace();
            }

            }
        } catch (PIMException ex) {
            ex.printStackTrace();
        }
       }
       //my_list.addItem(all_contact_lists);
       my_list.setRenderingPrototype("WWWWWWWWWWWWWWWWWWWW");
       my_form.addComponent(my_list);
       my_form.show();
       }
    public void pauseApp(){}
    public void destroyApp(boolean unconditional){}


}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

想你只要分分秒秒 2024-12-25 20:20:32

如果您使用电话号码发送短信或拨打电话,则只需一行代码即可完成。现在很明显,手机软件问题可能会影响应用程序访问 PIM API 的方式。此外,如果手机联系人设置中使用的内存设置为 SIM(单独),则您无法访问手机内存中的联系人,反之亦然,请确保两者都在使用中。如果您仍然遇到问题,请尝试此操作,

//make a text field in LWUIT that is declared globally

PhnNmbr = new TextField();

//set it to only accept phonenumber

PhnNmbr.setConstraint(TextField.PHONENUMBER);

//tell the user how to access phonebook

PhnNmbr.setHint("Press T9 then 'Search' to search phonebook");

//add a button or command 
//that either sends an sms to
//or calls the number in the text field
//or anything else you want to do with it

当用户按 T9 时,TextField 被视为带有参数 PHONENUMBER 的 LCDUI 文本字段,它允许它在 Sim 和手机内存中搜索联系人,这就是为什么您会注意到搜索命令(通常位于底部中心)。另请确保手机使用的内存同时设置为“Phone”(电话)和“Sim”(SIM)。

If you are using the phone number for a text or to call you can do that with only one line of code. Its now evident that phone software issues can affect the way the app accesses the PIM API. Also, if memory in use in the phones contact settings is set to SIM(alone), you can't access contacts in phone memory and vice versa, make sure both are in use. Try this if you still have an issue,

//make a text field in LWUIT that is declared globally

PhnNmbr = new TextField();

//set it to only accept phonenumber

PhnNmbr.setConstraint(TextField.PHONENUMBER);

//tell the user how to access phonebook

PhnNmbr.setHint("Press T9 then 'Search' to search phonebook");

//add a button or command 
//that either sends an sms to
//or calls the number in the text field
//or anything else you want to do with it

When the user presses T9, the TextField is considered an LCDUI text field with parameter PHONENUMBER which allows it to search for contacts in both Sim and phone memory, thats why you'll notice a Search command(usually at the bottom center). Also make sure that the memory in use for the phone is set to both Phone and Sim.

仅此而已 2024-12-25 20:20:32

PIM javadoc 的摘录

PIMItems 通过字段引用其数据。字段是一组
数据值都具有相似的特征。一个例子
字段是 TEL,表示该特定字段的数据值
是电话号码。实现 PIMItem 接口的类
定义该特定类的可能字段(例如,TEL 是
在联系人界面中定义为联系人可以使用的字段
支持)。

PIM 实现不需要支持所有可能的
在实现 PIMItem 接口的类中定义的字段。

是因为没有本地 PIM 数据库包含定义的所有字段
在此 API 中。 PIMItem 所属的 PIMList 决定了
PIMItem 可以支持和存储的字段(特定中的所有 PIMItem
PIMList 支持相同的字段集)。这
来自特定 PIMItem 的 PIMList.getSupportedFields() 方法
PIMList 用于查找此字段中支持哪些字段
物品。由于并非所有可能的字段实际上都受支持
特定的 PIMItem,应检查所有字段是否支持
项目的 PIMList 在使用之前使用 PIMList.isSupportedField(int)
以任何检索或存储方法。

每个字段都有以下可用信息:

  • 零个或多个与字段关联的数据值
  • 字段数据值的属性
  • 字段的描述性标签
  • 与字段关联的数据的数据类型

。可以在此链接读取

。检查设备是否支持 PIM 字段 Contact.NAMEContact.TEL。如果没有,那么您需要调用 PIMList.getSupportedFields() 来获取设备上支持的字段,并相应地获取该设备的名称和电话号码。如果我没记错的话,名称的替代字段是 Contact.FORMATTED_NAME

An excerpt from PIM javadoc

PIMItems reference its data through fields. A field is a grouping of
data values that all have similar characteristics. An example of a
field is TEL, which indicates data values for that particular field
are telephone numbers. Classes implementing the PIMItem interface
defines the possible fields that for that specific class (e.g TEL is
defined in the Contact interface as a field that a contact may
support).

PIM implementations are not required to support all of the possible
fields defined in the classes implementing the PIMItem interface.
This
is because no native PIM databases contain all of the fields defined
in this API. The PIMList that a PIMItem belongs to determines what
fields a PIMItem can support and store (all PIMItems in a particular
PIMList support the same set of fields). The
PIMList.getSupportedFields() method from a particular PIMItem's
PIMList is used to find out what fields are supported within this
item. Since not all possible fields are actually supported in a
particular PIMItem, all fields should be checked for support in the
item's PIMList using PIMList.isSupportedField(int) prior to being used
in any retrieval or storage method.

Each field has the following pieces of information available for it:

  • Zero or more data values associated with the Field
  • Attributes for data values for the Field
  • Descriptive label for the Field
  • Data Type of the data associated with the Field

Complete PIM javadoc can be read at this link.

Check if the device support's PIM Fields Contact.NAME and Contact.TEL on your device. If not then you need to call PIMList.getSupportedFields() to get the supported field on device and accordingly fetch the name and the telephone number for that device. If I remember correct, the alternative field for name is Contact.FORMATTED_NAME.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文