Samira
Samira

Reputation: 874

In SyncAdapter, Im calling requestSync but onPerfomSync is not calling

i'm desperate, can anyone help to fix this? in SyncAdapter, i'm calling requestSync but onPerfomSync is not calling! here is the code i've used:

my Onchange method is calling Correctly and i'm requesting for sync by requestSync but onPerformChange never called,

private class ContentObserverCLS extends ContentObserver {

    @Override
    public void onChange(boolean selfChange) {
        super.onChange(selfChange);

        final SessionManagement management = new SessionManagement(
                getApplicationContext());


            final Account account = new Account(management.getUserDetail()
                    .getUserName().toString(),
                    "com.myapp.account");

            final Bundle bundle = new Bundle();
            bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
            ContentResolver.requestSync(account,
                    ContactsContract.AUTHORITY, bundle);
        }
    }

}

public static class SyncAdapterImpl extends AbstractThreadedSyncAdapter {
    private final 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) {
        //TODO

    }
}

private static SyncAdapterImpl sSyncAdapter = null;
private static ArrayList<MobileContactInfo> phoneContacts;

public static void run(Context context, ServiceConnection connection) {

    Intent i = new Intent(context, ContactsSyncAdapterService.class);
    // Set the general action.
    i.setAction("ACTION_START");
    // Request to start.
    context.startService(i);
}

private ContentObserverCLS observerCLS;
private static SoapReceiveRequest getNewMobileContacts;

@Override
public IBinder onBind(Intent intent) {

    IBinder ret = null;
    ret = sSyncAdapter.getSyncAdapterBinder();

    final Handler handler = new Handler();
    observerCLS = new ContentObserverCLS(handler);
    getContentResolver().registerContentObserver(
            ContactsContract.Contacts.CONTENT_URI, true, observerCLS);

    return ret;
}

Upvotes: 0

Views: 322

Answers (1)

Utpal Sharma
Utpal Sharma

Reputation: 326

Try this in manifest

<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />

Upvotes: 1

Related Questions