Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I would like to intent to the android contact window to update or modify a user contact details. The code below works fine, however, it does not pass the correct phone number to the android contact editor window.

This is my code

 private void modifyContact() {
         phonenumber="0711236763";

    mSelectedContactUri=Uri.parse(phonenumber);

    mCursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);


    if (mCursor != null && mCursor.moveToFirst()) {
        mLookupKeyIndex = mCursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY);
        mCurrentLookupKey = mCursor.getString(mLookupKeyIndex);
        mIdIndex = mCursor.getColumnIndex(ContactsContract.Contacts._ID);
        mCurrentId = mCursor.getLong(mIdIndex);
    }

    mSelectedContactUri = ContactsContract.Contacts.getLookupUri(mCurrentId, mCurrentLookupKey);
    Intent editIntent = new Intent(Intent.ACTION_EDIT);

    editIntent.setDataAndType(mSelectedContactUri, ContactsContract.Contacts.CONTENT_ITEM_TYPE);
    editIntent.putExtra("finishActivityOnSaveCompleted", true);

    startActivity(editIntent);

    }

The variable phonenumber is the phone number for which i would like to modify or update.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
120 views
Welcome To Ask or Share your Answers For Others

1 Answer

Make sure the Cursor is initialized correctly before accessing data from it." it works in my code.

1.Try to position cursor by moveToFirst before reading data from it.

2.check for null-> if (c != null && c.moveToFirst()) {}

3.check for count-> (c != null && c.getCount() >0 && c.moveToFirst()){}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...