Kontakt hinzufügen

L

Lilithian

Ambitioniertes Mitglied
23
Hallo,

ich versuche gerade, per Button-Klick einen vorgegebenen Kontakt hinzuzufügen.
Durch googlen habe ich nur folgenden Code gefunden:

Code:
Intent i = new Intent(Intent.ACTION_INSERT_OR_EDIT);
                i.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
                i.putExtra(Insert.NAME, "Testname");
                startActivity(i);
Jedoch zeigt mir Eclipse die ganze Zeit die Meldung "ContactsContract cannot be resolved". Weiß jemand wie man dieses Problem beheben kann oder gibt es andere Möglichkeiten einen Kontakt hinzuzufügen?
 
Habe das ganze nun anders gelöst. Dabei gibt es aber die Probleme, dass die Klasse deprecated ist und dass die Adresse auch nicht wirklich in den richtigen Feldern steht, also wenn jemand noch eine andere, bessere Lösung hat... ;)

Code:
ContentValues personValues = new ContentValues();
                personValues.put(Contacts.People.NAME, "Testname");
                personValues.put(Contacts.People.STARRED, 0);

                Uri newPersonUri = Contacts.People.
                    createPersonInMyContactsGroup 
                    (context.getContentResolver(), personValues);

                if (newPersonUri != null) {
                    ContentValues mobileValues = new ContentValues();
                    Uri mobileUri = Uri.withAppendedPath(newPersonUri, 
                            Contacts.People.Phones.CONTENT_DIRECTORY);
                    mobileValues.put(Contacts.Phones.NUMBER, "123456789");
                    mobileValues.put(Contacts.Phones.TYPE,
                            Contacts.Phones.TYPE_WORK);
                    context.getContentResolver().insert(mobileUri,
                            mobileValues);
                    
                    ContentValues emailValues = new ContentValues();
                    Uri emailUri = Uri.withAppendedPath(newPersonUri,
                            Contacts.People.ContactMethods.CONTENT_DIRECTORY);
                    emailValues.put(Contacts.ContactMethods.KIND,
                            Contacts.KIND_EMAIL);
                    emailValues.put(Contacts.ContactMethods.TYPE, 
                            Contacts.ContactMethods.TYPE_WORK);
                    emailValues.put(Contacts.ContactMethods.DATA, 
                            "test@test.de");
                    context.getContentResolver().insert(emailUri, emailValues);
                    ContentValues addressValues = new ContentValues();
                    Uri addressUri = Uri.withAppendedPath(newPersonUri,
                            Contacts.People.ContactMethods.CONTENT_DIRECTORY);
                    addressValues.put(Contacts.ContactMethods.KIND, 
                            Contacts.KIND_POSTAL);
                    addressValues.put(Contacts.ContactMethods.TYPE, 
                            Contacts.ContactMethods.TYPE_WORK);
                    addressValues.put(Contacts.ContactMethods.DATA,
                        "Teststraße 5\n12345 Testort");
                    context.getContentResolver().insert(addressUri, addressValues);
}
 
"ContactsContract cannot be resolved" sollte nur in SDK <=1.6 vorkommen

Ich hatte ein ähnliches Problem. Da gibt es im netz irgendwo (is halt schon ne weile her) einen typen, der hat eine contact api für beide (SDK <=1.6 && SDK > 2.0 )möglichkeiten geschrieben.

Die war nicht perfekt, aber die hauptfunktionalitäten haben sehr gut funktioniert.
 
Zuletzt bearbeitet:
  • Danke
Reaktionen: Lilithian
Alles klar, dann versuch ich mal etwas in die Richtung zu finden, es soll nämlich ab SDK 1.6 und aufwärts laufen. Danke dir schon mal.
 

Ähnliche Themen

E
Antworten
2
Aufrufe
777
ekaya999
E
W
Antworten
14
Aufrufe
2.199
washpuda
W
O
Antworten
13
Aufrufe
986
Oli95
O
Zurück
Oben Unten