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