2016-03-19 6 views
0

Xamarinの連絡先に複数の電話番号を更新するためにアンドロイドアプリを作成しようとしています。私は以下のコードを見つけましたが、Javaの(私はすでにのC#にchangeвのjavaを持っている)XamarinのPhoneInfo Javaクラス

public void MultipleNulbers(int allPhoneNumbersLength, string Id) 
    { 
     List<ContentProviderOperation> ops = new List<ContentProviderOperation>(); 
     for (int j = 0; j < allPhoneNumbersLength; j++) 
     { 
      PhoneInfo phoneInfo = (PhoneInfo)allPhoneNumbers.ElementAt(j); 
      int phoneType = phoneInfo.GetIndex(); // phoneType = Phone.TYPE_HOME, Phone.TYPE_WORK, etc 
      ContentProviderOperation.Builder builder = ContentProviderOperation.NewUpdate(ContactsContract.Data.ContentUri); 
      builder.WithSelection(ContactsContract.Data.InterfaceConsts.RawContactId + "=?" + " AND " + 
            ContactsContract.Data.InterfaceConsts.Mimetype + "=?" + " AND " + 
            ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Type + "=?", new String[] 
            { 
             Convert.ToString(Id), 
             ContactsContract.CommonDataKinds.Phone.ContentItemType, 
             Convert.ToString(phoneType) 
            }); 
      builder.WithValue(ContactsContract.CommonDataKinds.Phone.Number, redactTextNumber.Text); 
      builder.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Type, 
           ContactsContract.CommonDataKinds.Phone.InterfaceConsts.TypeCustom); 
      ops.Add(builder.Build()); 
      this.ContentResolver.ApplyBatch(ContactsContract.Authority, ops); 
     } 
    } 

しかし、Visual Studioは、携帯電話の情報クラスを理解しません。 1つの連絡先の異なる電話番号を更新する方法がいくつかありますか、またはXamarinのPhoneInfoをどのように置き換えることができますか。

+0

PhoneInfoは標準のAndroidクラスではありません。どこから元のJavaサンプルを入手しましたか? allPhoneNumbersはどこから来たのですか? – Jason

+0

http://stackoverflow.com/questions/14785210/update-multiple-phone-numbers-in-contact –

+0

http://stackoverflow.com/questions/14785210/update-multiple-phone-numbers-in-contact –

答えて

0
public Dictionary<string, int> RedactPhoneNumbers(string Id) 
    { 
     Dictionary<string, int> numbersAndTypes = new Dictionary<string, int>(); 
     List<string> allNumbers = new List<string>(); 
     List<int> allTypes = new List<int>(); 
     ContentResolver cr = ContentResolver; 
     ICursor pCur = cr.Query(ContactsContract.CommonDataKinds.Phone.ContentUri, null, 
           ContactsContract.CommonDataKinds.Phone.InterfaceConsts.ContactId + " = ?", new String[] 
           { 
            Id 
           }, 
           null); 
     while (pCur.MoveToNext()) 
     { 
      int phNumber = pCur.GetColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.Number); 
      allNumbers.Add(pCur.GetString(phNumber)); 
      ICursor lCur = cr.Query(ContactsContract.CommonDataKinds.Phone.ContentUri, new String[] 
            { 
             ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Type, 
             ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label 
            }, 
            ContactsContract.CommonDataKinds.Phone.Number + " = ?", new String[] 
            { 
             Convert.ToString(phNumber) 
            }, 
            null); 
      while (lCur.MoveToNext()) 
      { 
       int lblIndex = lCur.GetColumnIndex(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label); 
       allTypes.Add(lCur.GetInt(lblIndex)); 
      } 
      lCur.Close(); 
     } 
     pCur.Close(); 
     numbersAndTypes = allNumbers.ToDictionary(x => x, x => allTypes[allNumbers.IndexOf(x)]); 
     return numbersAndTypes; 
    } 
+0

私はラベルを取得する権利を要求するplzを助ける。私の方法は、辞書に任意のラベルを取得しないでください –