爲電話聯繫人
try
{
String[] PROJECTION=new String[] {Contacts._ID,
Contacts.DISPLAY_NAME,
Phone.NUMBER
};
Cursor c=managedQuery(Phone.CONTENT_URI,
PROJECTION, null, null, null);
if (c.moveToFirst()) {
String ClsPhonename = null;
String ClsphoneNo = null;
do
{
ClsPhonename = c.getString(c.getColumnIndex(Contacts.DISPLAY_NAME));
ClsphoneNo = c.getString(c.getColumnIndex(Phone.NUMBER));
ClsphoneNo.replaceAll("\\D", "");
ClsPhonename=ClsPhonename.replaceAll("&", "");
ClsPhonename.replace("|","");
String ClsPhoneName=ClsPhonename.replace("|","");
}
} while(c.moveToNext());
}
爲SIM卡聯繫人
字符串ClsSimPhonename = NULL; String ClsSimphoneNo = null;
Uri simUri = Uri.parse("content://icc/adn");
Cursor cursorSim = this.getContentResolver().query(simUri,null,null,null,null);
while (cursorSim.moveToNext())
{
ClsSimPhonename =cursorSim.getString(cursorSim.getColumnIndex("name"));
ClsSimphoneNo = cursorSim.getString(cursorSim.getColumnIndex("number"));
ClsSimphoneNo.replaceAll("\\D","");
ClsSimphoneNo.replaceAll("&", "");
ClsSimPhonename=ClsSimPhonename.replace("|","");
System.out.println("SimContacts"+ClsSimPhonename);
System.out.println("SimContactsNo"+ClsSimphoneNo);
dts.createDatabse("MyCellFamily",getApplicationContext());
}
}
catch(Exception e)
{
e.printStackTrace();
}
也許在ACCOUNT_TYPE中存在拼寫錯誤?試試'com.android.contacts.sim'。 – Ash 2012-01-18 10:56:10
ohh對不起,我輸入了一個錯誤,但事實並非如此:)我會編輯這個 – sampathpremarathna 2012-01-18 10:59:24
你有沒有找到解決方案? – 2012-07-09 14:50:51