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 6194365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:17:03+00:00 2026-05-24T03:17:03+00:00

My code is as following Permission <uses-permission android:name=android.permission.WRITE_CONTACTS /> And caller Activity code is

  • 0

My code is as following

Permission

<uses-permission android:name="android.permission.WRITE_CONTACTS" />

And caller Activity code is

Intent addNewContact = new Intent(Intent.ACTION_INSERT);
addNewContact.setType(ContactsContract.Contacts.CONTENT_TYPE);  
startActivityForResult(addNewContact, ADD_NEW_CONTACT); // ADD_NEW_CONTACT = 2 for my specific purpose

And onActivityResult of caller Activity as

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        Log.i("OnActivityResult Test ", "Request code  : " + requestCode
                + "   " + " ResultCode   : " + resultCode);
        switch(requestCode) {           

            case 2: 
                  if (resultCode == Activity.RESULT_OK) {
                // code to Update my list view
                  }

        }
    }

My list view gets update on emulator and device (I checked with samsung galuxy) also other than Droid-X, so result doesn’t reflect on list if I am using Droid-X.

When I read Log cat msg of Droid-X I saw resultCode is always 0 (ZERO), even if I am adding new contact.

  • 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-05-24T03:17:05+00:00Added an answer on May 24, 2026 at 3:17 am

    I know that the problem with Droid-X, motoblur is that (per moto’s website) the blur contacts API is based off of the old Contacts API found in Android 1.x, and not the new 2.x ContactsContract API. It’s possible that HTC does the same.

    Ref :

    1. Created contacts not showing up on HTC Evo

    2. New contacts created using ContactsContract do not appear in Contacts app

    In your case you didn’t get result code as -1, when you are adding new contact. So better way don’t do any task (if you doing when contact is added) in onActivityResult . Extend ContentObserver class that will receive call backs for changes to content, and you can do your task.

    Ref :
    1. How to implement an Android ContentObserver

    And here is a sample example

    public class Test extends Activity {
    
        private NewContentObserver contentObserver = null;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout._layout);  
    
            //do another task
    
            //Adding listener when new contact will be added in device. 
            contentObserver = new NewContentObserver();
            this.getApplicationContext().getContentResolver().registerContentObserver (ContactsContract.Contacts.CONTENT_URI, true, contentObserver);        
        }
    
        @Override
        protected void onResume() {
            super.onResume();
    
        }
    
        @Override
        protected void onDestroy() {
            super.onDestroy();
            // unregister the provider 
    
            this.getApplicationContext().getContentResolver().unregisterContentObserver(contentObserver);
        }
    
    //Get newest contact
        private Uri getNewestContactUri() { 
            String[] projection = new String[] {ContactsContract.Contacts._ID}; 
            String orderBy = ContactsContract.Contacts._ID + " DESC"; 
            Cursor cursor = TagsActivity.this.getContentResolver().query( 
                    ContactsContract.Contacts.CONTENT_URI, projection, null, null, orderBy); 
            int idIdx = -1; 
            try { 
                    idIdx = cursor.getColumnIndexOrThrow(ContactsContract.Contacts._ID); 
            } catch (Exception e) { 
                    e.printStackTrace(); 
                    idIdx = -1; 
            } 
            if (idIdx != -1) { 
                    int id = -1; 
                    if (cursor.moveToFirst()) { 
                            id = cursor.getInt(idIdx); 
                    } 
                    if (id != -1) { 
                            return Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, 
                                            Integer.toString(id)); 
                    } 
            } 
            return null; 
        } 
    
        private class NewContentObserver extends ContentObserver {
    
            public NewContentObserver() {
                super(null);
            }
    
            @Override
            public void onChange(boolean selfChange) {
                super.onChange(selfChange);
    
                Uri contactData = getNewestContactUri();
            Cursor cursor = managedQuery(contactData, null, null, null, null);
            if (cursor.moveToFirst()) {
            long newId = cursor.getLong(cursor.getColumnIndexOrThrow(Contacts._ID));
            String newDisplayName = cursor.getString(cursor.getColumnIndexOrThrow(Contacts.DISPLAY_NAME));
            Log.i("Test", "New contact Added.  ID of newly added contact is : " + newId + " Name is : " + newDisplayName);
            runOnUiThread(addNewContactToList);
            }
            }
    
            @Override
            public boolean deliverSelfNotifications() {
                return true;
            }
        }
    
       //Since we cant update our UI from a thread this Runnable takes care of that! 
        private Runnable addNewContactToList = new Runnable() {
            public void run() {
                //add logic to update your list view
            }
        };
    }
    

    Hope this will help.

    Update : Contacts 2.x API works on MOTOBLUR phones running Gingerbread (Android 2.3) or higher. My Droid X is running Moto’s new Gingerbread, and I’m quite pleased that this now works.

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

Sidebar

Related Questions

I've set the following my android manifest: <uses-permission android:name=android.permission.WRITE_EXTERNAL_STORAGE /> I've got the following
i am using following code in my app: import android.app.Activity; import android.os.Bundle; import android.text.Html;
TL;DR We need to move <uses-permission android:name=android.permission.INTERNET/> under </application> Original question Hi, I am
I have the following code in my android project: locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria
I used following code for downloading XML file from ftp to android phone memory
I am a AS3 novice learning PureMVC and want to write code following best
The following code works great in IE, but not in FF or Safari. I
The following code doesn't compile with gcc, but does with Visual Studio: template <typename
The following code illustrates an object literal being assigned, but with no semicolon afterwards:
The following code should find the appropriate project tag and remove it from the

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.