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

Robolectric, create Thread without looper
How can i achieve this in android with proper clicks?(encircled in the image)
RenderScript package does not exist - although added to build.gradle
Android HttpHelper
encoding problems from text file Android
Writing files internally
Lazy loading not working for RecyclerView using Volley
App crash in Android M
DialogFragment doesn't show when set onDismiss
Why is my app is crashing with IllegalArgumentException?
How to use custom created drawable images for Android watch Face
Getting error when trying to parse a json object
How to get my phone number? [duplicate]
Drawer Toggle indicator “hamburger” doesn't animate until after initial orientation change
How download image with UniversalImageLoader
Turn off error messages android

Categories

HOME
django
jmeter
wakanda
github-for-windows
redux-form
case
replace
alarm
scripting
web-hosting
pyqt4
nested-if
regular-language
dkim
heap
plist
resultset
cmdb
openbugs
tput
comsol
dynatrace
symmetricds
android-intent
azure-iot-hub
glyphicons
scsi
topology
selinux
simpleitk
rubymotion
spring-async
joptionpane
exit
event-store
tosca
resourcebundle
roundup
stackexchange
errbot
user-defined-functions
winpe
eviews
anki
python-2.6
github3.py
sharding
installscript
mnist
openalpr
git-rewrite-history
movilizer
claims
file-sharing
apache-spark-dataset
procfile
robomongo
spring-integration-sftp
vugen
activeperl
bbpress
type-theory
grails-plugin
redistributable
google-cloud-console
flex4.6
uicolor
signalr.client
cifilter
gogs
clipboard.js
google-query-language
stream-processing
bizagi
jbase
spring-retry
atan2
forwarding
branch-and-bound
liquid-layout
snoop
git-ftp
user-permissions
bcache
code-documentation
rapidsvn
angular-gettext
boost-program-options
imagefilter
jama
named-parameters
jquery-slider
paste
twitter-bootstrap-rails
getopt
mongohq
kogrid
flex++
traceability
wp7test
server-administration
subgraph
appjs
apache-whirr
update-statement
mysql-error-1205
globals
jqueryform
interprocess
application-verifier
pos-for-.net
mathematical-notation
sqlobject

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