title: Add Custom Contact row in Phonebook like Whatsapp
body: <p>Basically what I need to achieve is very clear but I am having many doubts in my implementation. I went through R &amp; D about this topic but didn't find satisfied answer. Hope you guys will understand me and help me further.</p>
  
  <p>So here is screen shot for what I want to do:</p>
  
  <p>Contact detail page</p>
  
  <p><img src="https://i.stack.imgur.com/1JYRG.png" alt="image"></p>
  
  <p>What I did till now:</p>
  
  <p>Manifest.xml</p>
  
  <pre><code>        &lt;activity
              android:name=".AddCardActivity"
              android:screenOrientation="portrait"
              android:theme="@style/AppTheme.NoActionBar"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
                  &lt;!--&lt;data android:mimeType="vnd.android.cursor.item/vnd.ccc.in.businesscard" /&gt;--&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;service
              android:name=".customcontact.AccountAuthenticatorService"
              android:exported="true"
              android:process=":auth"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.accounts.AccountAuthenticator" /&gt;
              &lt;/intent-filter&gt;
              &lt;meta-data
                  android:name="android.accounts.AccountAuthenticator"
                  android:resource="@xml/authenticator" /&gt;
          &lt;/service&gt;
  
          &lt;service
              android:name=".customcontact.ContactsSyncAdapterService"
              android:exported="true"
              android:process=":contacts"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.content.SyncAdapter" /&gt;
              &lt;/intent-filter&gt;
  
              &lt;meta-data
                  android:name="android.content.SyncAdapter"
                  android:resource="@xml/sync_contacts" /&gt;
              &lt;meta-data
                  android:name="android.provider.CONTACTS_STRUCTURE"
                  android:resource="@xml/contacts" /&gt;
          &lt;/service&gt;
  </code></pre>
  
  <p>Here in intent-filter tag should I need to define <code>mime-type</code>? If I define <code>mime-type</code> as above my application is not being listed in Application list of device.</p>
  
  <p>Permissions in Manifest.XML:</p>
  
  <pre><code>&lt;uses-permission
          android:name="android.permission.AUTHENTICATE_ACCOUNTS"
          android:maxSdkVersion="22" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.READ_CONTACTS" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_CONTACTS" /&gt;
      &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;
      &lt;uses-permission android:name="android.permission.MANAGE_ACCOUNTS" /&gt;
      &lt;uses-permission android:name="android.permission.READ_SYNC_SETTINGS" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" /&gt;
  </code></pre>
  
  <p>authenticator.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
      android:accountPreferences="@xml/account_preferences"
      android:accountType="ccc.in.businesscard.account"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:smallIcon="@mipmap/ic_launcher" /&gt;
  </code></pre>
  
  <p>account_preferences.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;PreferenceScreen
      xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;!--&lt;PreferenceCategory--&gt;
          &lt;!--android:title="General Settings" /&gt;--&gt;
  
      &lt;!--&lt;PreferenceScreen--&gt;
          &lt;!--android:key="account_settings"--&gt;
          &lt;!--android:title="Account Settings"--&gt;
          &lt;!--android:summary="Sync frequency, notifications, etc."&gt;--&gt;
          &lt;!--&lt;intent--&gt;
              &lt;!--android:action="fm.last.android.activity.Preferences.ACCOUNT_SETUP"--&gt;
              &lt;!--android:targetPackage="fm.last.android"--&gt;
              &lt;!--android:targetClass="fm.last.android.activity.Preferences" /&gt;--&gt;
      &lt;!--&lt;/PreferenceScreen&gt;--&gt;
  &lt;/PreferenceScreen&gt;
  </code></pre>
  
  <p>Don't know much about this file.</p>
  
  <p>sync_contacts.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
      android:accountType="ccc.in.businesscard.account"
      android:contentAuthority="com.android.contacts"
      android:supportsUploading="false" /&gt;
  </code></pre>
  
  <p>contacts.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ContactsSource xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;ContactsDataKind
          android:detailColumn="data3"
          android:detailSocialSummary="true"
          android:icon="@mipmap/ic_launcher"
          android:mimeType="vnd.android.cursor.item/vnd.ccc.in.businesscard"
          android:summaryColumn="data2"/&gt;
  &lt;/ContactsSource&gt;
  </code></pre>
  
  <p>AddCardActivity.java</p>
  
  <pre><code>    @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_add_card);
  
          addAccount("MyNewServiceNumber", "123456");
      }
  
  
  
  private void addAccount(String userName, String password) {
          Account account = new Account(userName, getString(R.string.ACCOUNT_TYPE));
          AccountManager am = AccountManager.get(this);
          Bundle bundle = new Bundle();
          bundle.putString("Mobile", "+911111111111");
          boolean accountCreated = am.addAccountExplicitly(account, password, bundle);
  
          Bundle extras = getIntent().getExtras();
          if (extras != null) {
              if (accountCreated) {  //Pass the new account back to the account manager
                  AccountAuthenticatorResponse response = extras.getParcelable(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
                  Bundle result = new Bundle();
                  result.putString(AccountManager.KEY_ACCOUNT_NAME, userName);
                  result.putString(AccountManager.KEY_ACCOUNT_TYPE, getString(R.string.ACCOUNT_TYPE));
                  response.onResult(result);
              }
          }
          addContactTag(account,"+911111111111");
          Toast.makeText(getBaseContext(), "Account added", Toast.LENGTH_SHORT).show();
      }
  
   public void addContactTag(Account account, String number) {
  
          ArrayList&lt;ContentProviderOperation&gt; operationList = new ArrayList&lt;ContentProviderOperation&gt;();
  
          //  Create our RawContact
          ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI);
          builder.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, account.name);
          builder.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, account.type);
          operationList.add(builder.build());
  
          //  Create a Data record of common type 'Phone' for our RawContact
          builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
          builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0);
          builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
          builder.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, number);
          operationList.add(builder.build());
  
  
          builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
          builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0);
          builder.withValue(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/vnd.ccc.in.businesscard");
          builder.withValue(ContactsContract.Data.DATA1, number);
          builder.withValue(ContactsContract.Data.DATA2, "ourservice user");
          builder.withValue(ContactsContract.Data.DATA3, "Go to ourservice profile");
          operationList.add(builder.build());
  
  
          try {
              ContentResolver mContentResolver = getContentResolver();
              mContentResolver.applyBatch(ContactsContract.AUTHORITY, operationList);
              Log.d("addContactTag", "addContact batch applied");
              Toast.makeText(getBaseContext(), "Contact added", Toast.LENGTH_SHORT).show();
          } catch (Exception e) {
              Log.e("addContactTag", "Something went wrong during creation! " + e);
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>This is it. Let me know where I am doing wrong? Some doubts I faced:</p>
  
  <ol>
  <li><p>Why we need to add Account in device Settings?</p></li>
  <li><p>I can see that my code is only to add new record. How can I update specific contact to add custom row.</p></li>
  </ol>
  
  <p>Till now with above code, my application is only listed in Accounts section in Settings menu. I want to add custom row in my contact list who are using my application. </p>
  
  <p>Please help me with this scenario. Thanks in advance!</p>