无法访问/读取诺基亚中的 SIM 电话簿
我正在尝试访问诺基亚 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用电话号码发送短信或拨打电话,则只需一行代码即可完成。现在很明显,手机软件问题可能会影响应用程序访问 PIM API 的方式。此外,如果手机联系人设置中使用的内存设置为 SIM(单独),则您无法访问手机内存中的联系人,反之亦然,请确保两者都在使用中。如果您仍然遇到问题,请尝试此操作,
当用户按 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,
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.
PIM javadoc 的摘录
。可以在此链接读取
。检查设备是否支持 PIM 字段
Contact.NAME
和Contact.TEL
。如果没有,那么您需要调用PIMList.getSupportedFields()
来获取设备上支持的字段,并相应地获取该设备的名称和电话号码。如果我没记错的话,名称的替代字段是Contact.FORMATTED_NAME
。An excerpt from PIM javadoc
Complete PIM javadoc can be read at this link.
Check if the device support's PIM Fields
Contact.NAME
andContact.TEL
on your device. If not then you need to callPIMList.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 isContact.FORMATTED_NAME
.