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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:35:08+00:00 2026-06-02T08:35:08+00:00

I am trying to insert a contact through my application but i am not

  • 0

I am trying to insert a contact through my application but i am not able to figure out what should be the value of accountType and accountName as below.

ContentValues values = new ContentValues();
values.put(RawContacts.ACCOUNT_TYPE, accountType);
values.put(RawContacts.ACCOUNT_NAME, accountName);
Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values);
long rawContactId = ContentUris.parseId(rawContactUri);


values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
values.put(StructuredName.DISPLAY_NAME, "Mike Sullivan");
values.put(ContactsContract.CommonDataKinds.Phone.NUMBER,"1-800-111-411");
getContentResolver().insert(Data.CONTENT_URI, values);

Also when i try to execute this code with the following changes in the accountType and accountName, i am unable to see it in the Contacts.

values.put(RawContacts.ACCOUNT_TYPE, "acc_type");
values.put(RawContacts.ACCOUNT_NAME, "acc_name");

But it seems that some values get inserted as when i search for "Mike Sullivan" i get the contact but without the Phone Number.
Please Help

  • 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-02T08:35:10+00:00Added an answer on June 2, 2026 at 8:35 am

    below is the code to add contact database and also it return whether the contact was added or not::::

    //to save contact in Database
    public boolean SaveContact(Activity _activity,String name,String number) {
        String MIMETYPE_RADUTOKEN   = "vnd.android.cursor.item/radutoken";
        String  szname = name,szMobile = number;
        //Create a new contact entry!
        String szToken = String.format("RADU_TOKEN_%d", System.currentTimeMillis());
        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
        int rawContactInsertIndex = ops.size();
    
        ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI).withValue(RawContacts.ACCOUNTTYPE, null).withValue(RawContacts.ACCOUNT_NAME, null).build());
    
        //INSERT NAME
        ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,rawContactInsertIndex).withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE).withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, szname).build());
    
        //INSERT PINLESSMAX MOBILE NUMBER
        ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,   rawContactInsertIndex).withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE).withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, szMobile).withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM).withValue(ContactsContract.Data.DATA3, "PinLessMax").build());
    
        // SAVE CONTACT IN BCR Structure
        Uri newContactUri = null;
        //PUSH EVERYTHING TO CONTACTS
        try{
           ContentProviderResult[] res = _activity.getContentResolver().applyBatch(ContactsContract.AUTHORITY,ops);
          if (res!=null && res[0]!=null) {
             newContactUri = res[0].uri;    
         }
        }catch (RemoteException e) { 
            // error
            newContactUri = null;
        }  catch (OperationApplicationException e)   {
            // error
             newContactUri = null;
        }  
        if (newContactUri == null) {
            return false;
         }
        boolean foundToken = false;
    
      // IDENTIFY Contact based on name and token
        String szLookupKey = "";
        Uri lkup = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_FILTER_URI, szname);
        ContentResolver cr = _activity.getContentResolver();
        Cursor idCursor = _activity.getContentResolver().query(lkup, null, null, null, null);
        // get all the names 
        while (idCursor.moveToNext()) {
            String szId = idCursor.getString(idCursor.getColumnIndex(ContactsContract.Contacts._ID));
            String szName = idCursor.getString(idCursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            szLookupKey = idCursor.getString(idCursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
           // for this contact ID, search the custom field
           String tokenWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; 
          String[] tokenWhereParams = new String[]{szId, MIMETYPE_RADUTOKEN}; 
          Cursor tokenCur = cr.query(ContactsContract.Data.CONTENT_URI, null, tokenWhere, tokenWhereParams, null); 
          while (tokenCur.moveToNext()) {
             String token = tokenCur.getString(tokenCur.getColumnIndex(ContactsContract.Data.DATA1));
            // CHECK THE TOKEN!
            if (szToken.compareTo(token) == 0) {
              tokenCur.close();
              foundToken = true;
              break;
            }   
           } 
          tokenCur.close();
          if (foundToken) break;
      }
      idCursor.close();
      return true;
    }//SaveContact()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert a record into a table using Linq but get
I am trying to insert a string in MySQL table. But the following is
I am just trying to insert my xml data into a table through calling
I'm trying to insert and update a piece of information on an existing contact
I am trying to insert new RawContact contacts, but the RawContact added doesn't get
i'm trying to create a database with 4 columns(name,contact,date,mail) and i want to insert
I am trying to figure out how I would get the firstname and lastname
I have crated a form and trying to insert data using jquery ajax. But
Possible Duplicate: insert contacts into database but does not want to duplicate already existing
Trying to insert into a mongodb database from scala. the below codes dont create

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.