我一直在努力开发一款需要从SIM内存访问联系人的应用程序。这是我使用的代码,但有运行时异常。
{
Uri simUri = Uri.parse("content://icc/adn");
c=getContentResolver().query(simUri, null, null, null, null);
startManagingCursor(c);
getContacts();
}
private void getContacts(){
int i=0;
do {
// Get the field values
names[i++] = c.getString(0);
} while (c.moveToNext());
任何答案和解决方案都表示赞赏。你可以告诉我访问SIM卡联系人的确切URI吗? sim的联系人记忆表中是否有colums的名字?
答案 0 :(得分:0)
您的SIM卡联系人内容uri看起来是正确的。 我使用以下方法获取联系方式 -
private void allSIMContact() {
try {
String m_simPhonename = null;
String m_simphoneNo = null;
String m_id = null;
Cursor cursorSim = this.getContentResolver().query(simUri,
null, null, null, ContactsContract.Contacts.DISPLAY_NAME);
Log.i("PhoneContact", "total: " + cursorSim.getCount());
while (cursorSim.moveToNext()) {
m_id = cursorSim.getString(cursorSim.getColumnIndex("_id"));
m_simPhonename = cursorSim.getString(cursorSim
.getColumnIndex("name"));
m_simphoneNo = cursorSim.getString(cursorSim
.getColumnIndex("number"));
m_simphoneNo.replaceAll("\\D", "");
m_simphoneNo.replaceAll("&", "");
m_simPhonename = m_simPhonename.replace("|", "");
ListData contact= new ListData(Integer.parseInt(m_id),
m_simphoneNo, m_simPhonename, "", "", "", false);
arrayList.add(contact);
}
} catch (Exception e) {
e.printStackTrace();
}
}