gpt4 book ai didi

java-me - 无法访问/读取诺基亚 SIM 电话簿

转载 作者:行者123 更新时间:2023-12-01 02:41:07 26 4
gpt4 key购买 nike

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

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){}


}

最佳答案

如果您使用电话号码发短信或打电话,您只需一行代码即可完成。现在很明显,手机软件问题会影响应用程序访问 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。

关于java-me - 无法访问/读取诺基亚 SIM 电话簿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8322054/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com