Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update E-mail, Address, Nickname, etc of a contact in Android?

Does anyone know how to do that? Even links to some tutorials would help.

I'm using a device with Android 2.1.

like image 617
ngesh Avatar asked Jun 24 '11 09:06

ngesh


1 Answers

Please check below link

update contact details on Android


OR


Create XML file "editcontmain.xml"

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Button android:layout_width="fill_parent" android:id="@+id/EditContacts"
        android:onClick="@string/clickEvent" android:layout_height="wrap_content"
        android:text="Edit Contacts" />
</LinearLayout>

And Create java file "EditContMain.java"

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class EditContMain extends Activity {

    private static final int PICK_CONTACT = 0;
    private static final int EDIT_CONTACT = 1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.editcontmain);

    }

    public void clickHandler(View v) {
        switch (v.getId()) {
        case R.id.EditContacts:
            Intent intent = new Intent(Intent.ACTION_PICK,
                    ContactsContract.Contacts.CONTENT_URI);
            startActivityForResult(intent, PICK_CONTACT);
            break;
        default:
            break;
        }
    }

    @Override
    public void onActivityResult(int reqCode, int resultCode, Intent data) {
        super.onActivityResult(reqCode, resultCode, data);

        switch (reqCode) {
        case (PICK_CONTACT):

            if (resultCode == Activity.RESULT_OK) {

                Uri contactData = data.getData();
                Cursor c = managedQuery(contactData, null, null, null, null);

                Log.e("c", c.getCount() + "");
                if (c.moveToFirst()) {

                    String contactId = c.getString(c
                            .getColumnIndex(ContactsContract.Contacts._ID));

                    Toast.makeText(this, "ID = " + contactId, Toast.LENGTH_LONG)
                            .show();

                    Intent i = new Intent(Intent.ACTION_EDIT);
                    i.setData(Uri
                            .parse(ContactsContract.Contacts.CONTENT_LOOKUP_URI
                                    + "/" + contactId));
                    startActivityForResult(i, EDIT_CONTACT);
                }
            }

            break;    
        }
    }
}
like image 106
Nikhil Avatar answered Sep 22 '22 15:09

Nikhil