1
+ package net .yuki24 .examples .AccountManager .core ;
2
+
3
+ import android .accounts .Account ;
4
+ import android .accounts .OperationCanceledException ;
5
+ import android .app .Service ;
6
+ import android .content .AbstractThreadedSyncAdapter ;
7
+ import android .content .ContentProviderClient ;
8
+ import android .content .ContentResolver ;
9
+ import android .content .Context ;
10
+ import android .content .Intent ;
11
+ import android .content .SyncResult ;
12
+ import android .os .Bundle ;
13
+ import android .os .IBinder ;
14
+ import android .util .Log ;
15
+
16
+ public class ContactsSyncAdapterService extends Service {
17
+ private static final String TAG = "ContactsSyncAdapterService" ;
18
+ private static SyncAdapterImpl sSyncAdapter = null ;
19
+ private static ContentResolver mContentResolver = null ;
20
+
21
+ public ContactsSyncAdapterService () {
22
+ super ();
23
+ }
24
+
25
+ private static class SyncAdapterImpl extends AbstractThreadedSyncAdapter {
26
+ private Context mContext ;
27
+
28
+ public SyncAdapterImpl (Context context ) {
29
+ super (context , true );
30
+ mContext = context ;
31
+ }
32
+
33
+ @ Override
34
+ public void onPerformSync (Account account , Bundle extras , String authority , ContentProviderClient provider , SyncResult syncResult ) {
35
+ try {
36
+ ContactsSyncAdapterService .performSync (mContext , account , extras , authority , provider , syncResult );
37
+ } catch (OperationCanceledException e ) {
38
+ }
39
+ }
40
+ }
41
+
42
+ @ Override
43
+ public IBinder onBind (Intent intent ) {
44
+ IBinder ret = null ;
45
+ ret = getSyncAdapter ().getSyncAdapterBinder ();
46
+ return ret ;
47
+ }
48
+
49
+ private SyncAdapterImpl getSyncAdapter () {
50
+ if (sSyncAdapter == null ) sSyncAdapter = new SyncAdapterImpl (this );
51
+ return sSyncAdapter ;
52
+ }
53
+
54
+ private static void performSync (Context context , Account account , Bundle extras , String authority , ContentProviderClient provider , SyncResult syncResult )
55
+ throws OperationCanceledException {
56
+ mContentResolver = context .getContentResolver ();
57
+ Log .i (TAG , "performSync: " + account .toString ());
58
+ //This is where the magic will happen!
59
+ }
60
+ }
0 commit comments