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

IBM MobileFirst - Can't subscribe, notification token is not updated on the server
ScrollView goes out of view
Android build version automation in Git
Android - google maps v2 - How to clear map makers without blink
Is it possible to implement Admob in my app using Adobe Flash?
Change ImageView if JSON Object String is equivalent to a value
Load Image for cropping from Google Photos Gallery
How to disable the auto appear of statusBar in android in full screen mode
How to change the Android gallery selected item color?
What is executed in the NOT UI THREAD in a IntentService?
Android shape doesn't stretch as progressDrawable on seekbar
Storing multiple instances of Arraylist<LatLng> to shared prefences
Unable to add cordova platform android on Ubuntu 14.04
Calling “ getContentResolver ” in an Android Java class
What happens when only high resolution layouts are defined?
NoSuchFieldError -> BasicHeadValueFormatter.INSTANCE Android Studio

Categories

HOME
gdb
case
toolbox
tvos
nuget-package
special-characters
joomla3.0
teechart
32bit-64bit
dkim
stellar.js
onedrive-api
dynatrace
eip
event-sourcing
xmonad
shortest-path
jmp
imagemap
easeljs
beautifier
interbase
android-sharedpreferences
progress-bar
spring-security4
android-gridview
least-squares
apriori
softmax
movilizer
ovf
configurationmanager
identification
page-replacement
ngmaterial
offline.js
django-1.10
choice
node-request
envi
async.js
android-wake-lock
turbo-prolog
sklearn-pandas
thread-sleep
doctype
mod-proxy
dronekit-android
node-serialport
nodelist
primitive-types
sip-server
structuremap3
post-commit-hook
raygun
codeplex
spring-remoting
android-audiorecord
breakout
model-driven-development
jeromq
printdialog
ui-select2
jquery-1.9
resource-management
robotlegs
cakephp-1.2
cuda-gdb
convention
google-ajax-api
quotation-marks
appledoc
cloudfiles
cac
object-database
dot-emacs
binomial-heap
skype4java
lalr
leader
netbeans6.1

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