Android Open Source - seagull Contacts Manager






From Project

Back to project page seagull.

License

The source code is released under:

GNU General Public License

If you think the Android project seagull listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ru.perm.trubnikov.seagull;
/*ww  w  . j a v  a 2  s  .  c om*/
import java.util.ArrayList;

import android.accounts.Account;
import android.content.ContentProviderOperation;
import android.content.Context;
import android.provider.ContactsContract;
import android.provider.ContactsContract.AggregationExceptions;
import android.provider.ContactsContract.RawContacts;

public class ContactsManager  {
  
  public static void addSeagullContact(Context context, Account account, String name, long RawContactIdToMerge) {
    
    //Log.i(TAG, "Adding contact: " + name);
    ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();

    ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
    builder.withValue(RawContacts.ACCOUNT_NAME, account.name);
    builder.withValue(RawContacts.ACCOUNT_TYPE, account.type);
    builder.withValue(RawContacts.SYNC1, account.name);
    operationList.add(builder.build());

    builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
    builder.withValueBackReference(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0);
    builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
    builder.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name);
    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.ru.perm.trubnikov.seagull.profile");
    builder.withValue(ContactsContract.Data.DATA1, account.name);
    builder.withValue(ContactsContract.Data.DATA2, "?????");
    builder.withValue(ContactsContract.Data.DATA3, "?????? ????? ??????????");
    //builder.withValue(ContactsContract.Data.DATA4, "+79777777777");
    operationList.add(builder.build());
    
    
    // Merging
    builder = ContentProviderOperation.newUpdate(ContactsContract.AggregationExceptions.CONTENT_URI);
    builder.withValue(AggregationExceptions.TYPE, AggregationExceptions.TYPE_KEEP_TOGETHER);
    builder.withValue(AggregationExceptions.RAW_CONTACT_ID1, RawContactIdToMerge);
    builder.withValueBackReference(AggregationExceptions.RAW_CONTACT_ID2, 0);
    
    operationList.add(builder.build());

    try {
      context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, operationList);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }




  }




Java Source Code List

ru.perm.trubnikov.seagull.AccountAuthenticatorService.java
ru.perm.trubnikov.seagull.ContactsManager.java
ru.perm.trubnikov.seagull.ContactsSyncAdapterService.java
ru.perm.trubnikov.seagull.DbHelper.java
ru.perm.trubnikov.seagull.LoginActivity.java
ru.perm.trubnikov.seagull.MainActivity.java
ru.perm.trubnikov.seagull.ProfileActivity.java
ru.perm.trubnikov.seagull.SelectOperatorActivity.java