0
我在Xamarin中開發c#並試圖獲取聯繫人的號碼。我試過這樣:獲取聯繫人的號碼
private static int PICK_NUMAR = 1;
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 uri = data.Data;
string[] projection = new [] { ContactsContract.CommonDataKinds.Phone.Number };
using (Android.Database.ICursor c = ManagedQuery (uri, projection, null, null, null)) {
if (c != null) {
string NUMAR_TELEFON = c.GetString (c.GetColumnIndex (ContactsContract.CommonDataKinds.Phone.Number));
c.MoveToFirst();
FindViewById<EditText> (Resource.Id.Input2).Text = NUMAR_TELEFON;
}
}
}
}
但沒有奏效。我試圖進行調試,並且在ICursor的聲明後我看到代碼卡住了。我做錯了什麼?