我很绝望 有人可以帮忙解决这个问题吗? 在SyncAdapter中,我正在调用requestSync但onPerfomSync没有调用! 这是我用过的代码:
我的Onchange方法正确调用,我正在通过requestSync请求同步,但onPerformChange从未调用过,
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;
}
答案 0 :(得分:1)
在清单
中试试<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />