Skip to content

Commit 75b9f44

Browse files
committed
added the simplest example of contact sync that does nothing.
1 parent 6ea13fe commit 75b9f44

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

account-manager-example/AndroidManifest.xml

+6
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,11 @@
3030
</intent-filter>
3131
<meta-data android:name="android.accounts.AccountAuthenticator" android:resource="@xml/authenticator" />
3232
</service>
33+
<service android:name=".core.ContactsSyncAdapterService" android:exported="true" android:process=":contacts">
34+
<intent-filter>
35+
<action android:name="android.content.SyncAdapter" />
36+
</intent-filter>
37+
<meta-data android:name="android.content.SyncAdapter" android:resource="@xml/syncadapter" />
38+
</service>
3339
</application>
3440
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:contentAuthority="com.android.contacts"
3+
android:accountType="net.yuki24.examples"
4+
android:supportsUploading="false"
5+
android:userVisible="true" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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

Comments
 (0)