Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8858445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:49:51+00:00 2026-06-14T14:49:51+00:00

I have been developing a contact app, it allows : call, sms, delele, etc

  • 0

I have been developing a contact app, it allows : call, sms, delele, etc … and Edit Contact. When user click and hold on a contact, a context menu show (picture below). The actions call, sms, … was completed but Edit is n’t. Please give me some code or advice . Thanks in advance

Image is here.

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
        case R.id.call:
            //do something
            String mPhoneNumber = "tel:" + getPhoneNumber(mRecordId);
            Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(mPhoneNumber));
            startActivity(intent);
            return true;

        case R.id.message:
            //do something
            String mSmsNumber = getPhoneNumber(mRecordId);
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + mSmsNumber)));
            return true;

        case R.id.sendemail:
            //do something
            return true;
        case R.id.edit:
            //do something // need help???

            return true;
        case R.id.delete:
            //do something
            new AlertDialog.Builder(mContext).setMessage("Do you want to delete this contact?")
            .setTitle("Delete").setCancelable(false).setPositiveButton("Delete", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    deleteContactEntry(mRecordId);
                    populateContactList();
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    dialog.cancel();

                }
            }).show();

            return true;
        default:
            return super.onContextItemSelected(item);
    }

Here are methods i used:

/**
 * Populate the contact list based on account currently selected in the account spinner.
 */
private void populateContactList() {
    // Build adapter with contact entries
    Cursor cursor = getContacts();
    String[] fields = new String[] {
            ContactsContract.Data.DISPLAY_NAME
    };
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contact_entry, cursor,
            fields, new int[] {R.id.contactEntryText});
    mContactList.setAdapter(adapter);
}

/**
 * Obtains the contact list for the currently selected account.
 *
 * @return A cursor for for accessing the contact list.
 */
private Cursor getContacts()
{
    // Run query
    Uri uri = ContactsContract.Contacts.CONTENT_URI;
    String[] projection = new String[] {
            ContactsContract.Contacts._ID,
            ContactsContract.Contacts.DISPLAY_NAME
    };

    String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" +
            (mShowInvisible ? "0" : "1") + "'";


    // String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = 0"; 


    String[] selectionArgs = null;
    String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";

    return managedQuery(uri, projection, selection, selectionArgs, sortOrder);
}

/**
 * Launches the ContactAdder activity to add a new contact to the selected accont.
 */
protected void launchContactAdder() {
    Intent i = new Intent(this, ContactAdder.class);
    startActivity(i);
}

/**
 * Get Phone Number
 */
private String getPhoneNumber(long contactId){
    String mPhoneNumber = null;
    String [] colums = new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER };
    String where = ContactsContract.Data.RAW_CONTACT_ID + "=?";
    String[] whereParameters = new String[]{Long.toString(contactId)};
    Cursor contacts = getContentResolver().query(ContactsContract.Data.CONTENT_URI,colums,where, whereParameters, null);
       if (contacts.moveToFirst()) { 
              mPhoneNumber = contacts.getString(0);
           } 
           contacts.close(); 
           return mPhoneNumber; 
}

/**
 * Delete Contact
 */
private void deleteContactEntry(long contactId){
    //String [] projection = new String [] {ContactsContract.RawContacts._ID};

    String mSelectionClause = ContactsContract.RawContacts._ID + "=?";
    String [] mSelectionArgs = new String [] {Long.toString(contactId)};
    getContentResolver().delete(ContactsContract.RawContacts.CONTENT_URI, mSelectionClause, mSelectionArgs);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:49:52+00:00Added an answer on June 14, 2026 at 2:49 pm

    For Edit function you can use Edit intent to call default contact app

    Intent i = new Intent(Intent.ACTION_EDIT);
    i.setData(Uri.parse(ContactsContract.Contacts.CONTENT_LOOKUP_URI + "/" + id)); //contact's id
    startActivityForResult(i, idEDIT_CONTACT);
    

    For sending Email have a look at this question or this

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been developing an user interface with Java Swing, and I have met
I have been developing an app for weeks on a desktop computer. I have
I have been developing an app using the very easy-to-pickup Flask system and I
I have been developing test builds of an app for some time and have
I have been developing the application which can manage a device using SMS commands;
I have been developing the application which must catch all input sms. For it
I have been developing a basic app. Now at the deployment stage it has
I have been developing a web app using play framework for a while (using
I have been developing an app to show battery information. I have taken whatever
I have been developing an android app, and i wanted to test it out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.