我需要使用 Xamarin Forms/Android 的意圖以編程方式打開 Android 聯系人應用程序。當“添加新聯系人”活動/屏幕出現時,我想用以下字段預先填充它:名稱(正在填充)電話(正在填充)街道(無人居?。┏鞘校o人居?。顟B(未填充)國家(沒有看到這個字段,沒有填充)如上所述,某些屏幕正在填充,但地址字段并未填充。這是用于觸發打開 Android 的“添加聯系人”屏幕的活動的 Xamarin C# Android 代碼/服務:public void AddContact(string name, string[] phoneNumbers, string streetAddress, string city, string state, string postalCode, CountryValues countrycode)? ? {? ? ? ? // get current activity? ? ? ? var activity = CrossCurrentActivity.Current.Activity;? ? ? ? // create add contact intent? ? ? ? var intent = new Intent(Intent.ActionInsert);? ? ? ? intent.SetType(ContactsContract.Contacts.ContentType);? ? ? ? // add field for contact name? ? ? ? intent.PutExtra(ContactsContract.Intents.Insert.Name, name);? ? ? ? // Adding more than on phone number if available? ? ? ? foreach (string numbers in phoneNumbers)? ? ? ? {? ? ? ? ? ? intent.PutExtra(ContactsContract.Intents.Insert.Phone, numbers);? ? ? ? }? ? ? ? // pre-populate address fields? ? ? ? intent.PutExtra(ContactsContract.CommonDataKinds.StructuredPostal.Street, streetAddress);? ? ? ? intent.PutExtra(ContactsContract.CommonDataKinds.StructuredPostal.City, city);? ? ? ? intent.PutExtra(ContactsContract.CommonDataKinds.StructuredPostal.Region, state);? ? ? ? intent.PutExtra(ContactsContract.CommonDataKinds.StructuredPostal.Postcode, postalCode);? ? ? ? intent.PutExtra(ContactsContract.CommonDataKinds.StructuredPostal.Country, countrycode.ToString());? ? ? ? //start activity? ? ? ? activity.StartActivity(intent);? ? }該活動確實會在聯系人應用程序中打開“添加新聯系人”屏幕,但僅填充姓名和電話號碼字段。請參閱下面的屏幕截圖:我找到了一個可以轉換為 Xamarin.Android 的鏈接,但我一直在努力實現Java Samples。
1 回答

幕布斯7119047
TA貢獻1794條經驗 獲得超8個贊
我擔心您只能將 下可用的值作為參數傳遞ContactsContract.Intents.Insert
。因此,對于地址,您只有郵政編碼,如文檔中詳述:
public static Final String POSTAL:在 API 5 中添加
聯系郵政地址的額外字段。
類型:字符串
恒定值:“郵政”
因此,您可以按如下方式傳遞郵政編碼:
intent.PutExtra(ContactsContract.Intents.Insert.Postal,?postalCode);
您現在可能需要要求用戶在“添加聯系人”頁面中手動輸入其他值。
另外,您是否測試過使用列表同時添加多部手機?從文檔來看,您似乎應該使用SECONDARY_PHONE和TERTIARY_PHONE常量。
- 1 回答
- 0 關注
- 140 瀏覽
添加回答
舉報
0/150
提交
取消