0

I want to change the contact information from an app, is that possible?

What I want to do is to be able to create a contact with a specified name and add a specified number to 'this' contact within my app. But, this should be done automatically and not by the user.

I have created an android app that sends sms, but I want it to change the contact information if the sms is sent to the same phone...

In other words; if I send a sms to my phone, I want the app to create a contact for my own number and rename this number with a specified name.

I hope this is understandable... :P

GeCCo
  • 1
  • 1

2 Answers2

0

I don't know the exact way to do this but I think those examples can help:

Android ContactAdder

Android edit contact

Also editing a contact is performed through an Intent I believe, you need to create an intent like:

Intent i = new Intent(Intent.ACTION_EDIT);

and change info through this intent. Also see this:

Android update contact name

Hope it helps!

Community
  • 1
  • 1
ecem
  • 3,574
  • 3
  • 27
  • 40
0

please try this:

public static void addContact(Context context, String firstname, String surname, String number) {
    try {
        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

        ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI).withValue(RawContacts.ACCOUNT_TYPE, null).withValue(RawContacts.ACCOUNT_NAME, null).build());
        ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI).withValueBackReference(Data.RAW_CONTACT_ID, 0).withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE).withValue(StructuredName.GIVEN_NAME, firstname).withValue(StructuredName.FAMILY_NAME, surname).build());
        ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI).withValueBackReference(Data.RAW_CONTACT_ID, 0).withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE).withValue(Phone.NUMBER, number).withValue(Phone.TYPE, Phone.TYPE_MOBILE).build());

        ContentProviderResult[] res = context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
        if (res == null) { //error }
    } catch (RemoteException e) {
        // error
    } catch (OperationApplicationException e) {
        // error
    }
}
kingston
  • 11,053
  • 14
  • 62
  • 116