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

unable to startActivity master-detail from another activity
NumberPicker textColour
Change keyboard language in android programitically
Android apk taking gson.jar as a native platform
Android App for Tablet
Exception with Android WebView
Android: Binding dates to listview alongside other data
Updated collided sprite only
Get Public tweets Twitter API 1.1 [closed]
Space in SQLite query [closed]
Android: Clear Activity Stack [duplicate]
How to Set monogram to textview — android
Android Layout folder is not changing properly
ActionBarCompat and Navigation Drawer icon size
call start activity for result inside fragment class
Timer ends = application crash

Categories

HOME
phantom-dsl
adal
api
spark-streaming
developer-tools
string
dns
phpmyadmin
rdbms
pyqt
rsa
obfuscation
oracle-apex-5
tivoli
carousel
emscripten
tvos
extjs4.2
endeca
dynatrace
shortest-path
cfml
spring-async
question2answer
postscript
amazon-quicksight
firebase-analytics
ntp
event-flow
apic
parse-tree
ideascript
tex
google-data-api
dcmtk
wmp
linqpad
subclipse
placeholder
phpdbg
jquery-ui-draggable
spring-integration-sftp
trojan
corruption
video-conferencing
quicktime
payload
janus
filenet
javafx-css
lrs
myspace
respondcms
clipboard.js
stream-processing
lua-telegram-bot
rubaxa-sortable
sha512
branch-and-bound
liquid-layout
mirror
google-refine
aspectj-maven-plugin
uvc
umlgraph
actionfilterattribute
jbake
sql-scripts
paw
insight.database
malformedurlexception
radiant
authlogic
extjs2
synapse
ie8-compatibility-mode
oocss
inappsettingskit
neos-server
merb
font-awesome-4.0.0
chart-director
cakephp-1.2
iboutlet
appjs
fitbounds
entity-attribute-value
expression-blend-4
google-floodlight
mbeans
nhprof
lxr
contentpresenter
great-circle

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