android - SyncAdapter not getting called on "Network tickle" -


overview

i follwed google's tutorial on using syncadapter without using contentprovider, authenticator..etc. works when call onperformsync(...) when need "upload" server via de syncadapter.

now, can imagine, need downloads server (yes understand better use google's cloud messaing system, set given, , can't change that). that, instead of doing periodical syncs, want make use of "network tickle" android system carries out when there network available. state following:

contentresolver.setissyncable(accounts[0], authority, 1); contentresolver.setsyncautomatically(accounts[0], authority, true);  

but syncadapter is not getting called. looking other stackoverflow questions, there seem problem if targetting api 10 or below syncadapter , must add account explicitly before calling before methods. ended this:

accountmanager accountmanager = (accountmanager) context.getsystemservice(account_service);      account[] accounts = accountmanager.getaccounts();     if(accounts.length == 0){ //add dummy account         account newaccount = new account(account, account_type);         contentresolver.setissyncable(accounts[0], authority, 1);         contentresolver.setsyncautomatically(accounts[0], authority, true);          accountmanager.addaccountexplicitly(newaccount, null, null);     }else{          accounts = accountmanager.getaccounts();         contentresolver.setissyncable(accounts[0], authority, 1);            contentresolver.setsyncautomatically(accounts[0], authority, true);      } 

now code gets executed when user signs in, or if application killed , started again. wondering, should call setissyncable , setsyncautomatically when add dummyaccount first time?

also, part of "goodiness" of syncadapter keep on making calls in case of exception. don't quite understand how goes about, instead have this:

private void profileupdate(){        tableaccounts db = tableaccounts.getinstance(getcontext()); boolean isrecorddirty = db.isrecorddirty(signedinuser);     if(isrecorddirty){    if(server.updateuserprofile(signedinuser)){        db.cleandirtyrecord(signedinuser);        turnoffperiodicsync();    }else{        this.turnonperiodicsync(this.sync_bundle);       } }else      turnoffperiodicsync();  } 

as can see, depending on result of upload server, turn on or off periodic sync.

since accountmanager.getaccounts[] return every account on device, think nothing guarantee account[0] app's account (aka, has account_type of package name). -- call addaccountexplicitly() in case, if existed, nothing happens.

    account account = new account(account, account_type);      accountmanager accountmanager = (accountmanager) context.getsystemservice(context.account_service);     accountmanager.addaccountexplicitly(account, null, null)     context.getcontentresolver().setsyncautomatically(account, authority, true); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -