2016-03-19 4 views
0

Ich versuche, Android-App für die Aktualisierung Kontakt mehrere Telefonnummern auf Xamarin zu erstellen. Ich fand Code unten, aber auf Java (ich habe changeв Java bereits auf C#)PhoneInfo Java-Klasse in Xamarin

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); 
     } 
    } 

Aber Visual Studio nicht Telefoninfo Klasse verstehen. Ich würde gerne wissen, gibt es einige Methoden zum Aktualisieren verschiedener Telefonnummern von 1 Kontakt, oder wie kann ich PhoneInfo auf Xamarin ersetzen.

+0

PhoneInfo scheint keine standardmäßige Android-Klasse zu sein. Woher hast du das Original-Java-Sample? Woher kommen 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 –

Antwort

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

Helfen Sie mir PLZ richtige Anfrage, um Etiketten zu bekommen. Meine Methode bekommt keine Labels zum Wörterbuch –