android


SyncAdapter with ContactContract


i want to build a sync adapter to sync all contacts of my phone regardless its google contacts or phone contacts. and after that i will auto sync new contacts or updates for old contacts or notify my app when i delete a contact by using phone's default app. i made a account for my app through AbstractAccountAuthenticator and also made a sync adapter. Thanks in advance.
package com.icontects.icontects.Sync;
import android.accounts.Account;
import android.accounts.OperationCanceledException;
import android.app.Service;
import android.content.AbstractThreadedSyncAdapter;
import android.content.ContentProviderClient;
import android.content.ContentProviderOperation;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.content.SyncResult;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.BaseColumns;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.RawContacts;
import android.provider.ContactsContract.RawContacts.Entity;
import android.util.Log;
import java.util.ArrayList;
import java.util.HashMap;
public class ContactsSyncAdapterService extends Service {
private static final String TAG = "ContactsSyncAdapter";
private static SyncAdapterImpl sSyncAdapter = null;
private static ContentResolver mContentResolver = null;
public ContactsSyncAdapterService() {
super();
//android.os.Debug.waitForDebugger();
}
public static class SyncAdapterImpl extends AbstractThreadedSyncAdapter {
private Context mContext;
public SyncAdapterImpl(Context context) {
super(context, true);
mContext = context;
}
#Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
try {
ContactsSyncAdapterService.performSync(mContext, account, extras, authority, provider, syncResult);
} catch (OperationCanceledException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
#Override
public IBinder onBind(Intent intent) {
IBinder ret = null;
ret = getSyncAdapter().getSyncAdapterBinder();
return ret;
}
private SyncAdapterImpl getSyncAdapter() {
if (sSyncAdapter == null) sSyncAdapter = new SyncAdapterImpl(this);
return sSyncAdapter;
}
private static void performSync(Context context, Account account, Bundle extras, String authority,
ContentProviderClient provider, SyncResult syncResult) throws OperationCanceledException {
mContentResolver = context.getContentResolver();
}
}

Related Links

Toolbar custom theme title/subtitle padding issue
Why is this xamarin android menu text not showing?
why is the run button grayed out in Android Studio
Disable swiping in ViewPager
xamarin.forms image appears on all devices, but not on windows10 tablet
on button click get data from each view
how to apply jobschedular below lolipop
Add search functionality in list view
Android Location “going for a walk” by itself
Providing Integers.xml for different screen densities
Change UI for notification status bar - Android
Google Play Store : How to upload more APKs to support different CPU architectures
background drawable for using layer-list not wrapping the parent screen
Establishing connection from unity3d to android phone?
Spinner not showing selected or default choice
how to use adobe creative sdk in NDK based project

Categories

HOME
beautifulsoup
spark-streaming
nvd3.js
apache-jena
datastore
newrelic
nsbundle
soa
hpc
gluon-mobile
spin
syntaxnet
fabric.io
php-5.6
radgridview
flatpak
selectize.js
heat
gruntfile
microsoft-dynamics-nav
aws-sdk
google-data-studio
google-picker
shortest-path
simpleitk
easeljs
comparator
beta
motion-detection
pylons
mobx
utorrent
record
pdw-file-browser
swagger-php
docfx
xdocreport
nohup
amazon-ses
diacritics
google-data-api
p4merge
sharp-snmp
microsoft-metro
glm-math
facebook-social-plugins
puredata
httrack
jquery-ui-draggable
chai-as-promised
datamaps
manova
google-cse
reshape
gameplay-kit
ziparchive
latin
envi
respondcms
appscale
refinerycms
google-query-language
lua-telegram-bot
cda
database-relations
false-sharing
highland.js
decimalformat
tfs-workitem
wiredep
vigenere
batik
aspectj-maven-plugin
matlab-deployment
cross-join
mruby
nsmenu
draw2d-js
dsym
android-sdk-2.3
panda3d
mapping-by-code
oracle-enterprise-linux
hibernateexception
ikimagebrowserview
google-ajax-api
tournament
unattended-processing
undefined-index
vs-android
message-passing
folding
build-environment
httpcookie
change-management
idatareader

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App