0
我试图获取SIM卡和手机通讯录。我成功地与手机通讯录(手机联系人&同步联系人),但与虚拟联系人我失败... 我尝试了很多的URI,但没有人工作,所以我认为你们可以帮助我。Android - 显示SIM卡和手机通讯录
private void Click (object sender , EventArgs eventArgs)
{
Intent intent = new Intent (Intent.ActionPick , Android.Net.Uri.Parse ("content://contacts"));
intent.SetType (ContactsContract.Contacts.ContentType);
StartActivityForResult (intent , SMS_Send.PICK_NUMAR);
}
protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
{
if ((requestCode == SMS_Send.PICK_NUMAR) && (resultCode == Result.Ok) && (data != null)) {
Android.Net.Uri uriContact = data.Data;
ICursor cursor = ManagedQuery (uriContact,null,null,null,null);
if (cursor.MoveToFirst()) {
string NUME_CONTACT = cursor.GetString (cursor.GetColumnIndex(ContactsContract.Contacts.InterfaceConsts.DisplayName));
string NUMAR_TELEFON = getPhoneNumber (NUME_CONTACT);
ISharedPreferences NumeNumar = GetPreferences (FileCreationMode.Private);
ISharedPreferencesEditor Editor = NumeNumar.Edit();
Editor.PutString ("NUMAR_TELEFON" , NUMAR_TELEFON);
Editor.PutString ("NUME_CONTACT" , NUME_CONTACT);
Editor.Apply();
}
}
}
public string getPhoneNumber(string name)
{
string ret = null;
string selection = ContactsContract.Contacts.InterfaceConsts.DisplayName +" like '%" + name +"%'";
string[] projection = new string[] { ContactsContract.CommonDataKinds.Phone.Number };
ICursor c = ManagedQuery (ContactsContract.CommonDataKinds.Phone.ContentUri,projection,selection,null,null);
if (c.MoveToFirst()) {
ret = c.GetString (0);
}
return ret;
}
预先感谢您!
有一点很难理解一点,但谢谢你的好意 – Mihawai 2015-02-24 18:58:44