Being specific, I have a 'Droid HTC incredible, Android version 2.2, Baseband 2.15.00.07.28, kernel 2.6.32.17-g9a2fe16, Build 3.26.605.1, Software Number 3.26.605.1
I've got Eclipse and the Android SDK all installed and running OK. It's nice how I can debug and single step code executing on my Droid in Eclipse.
I have read a number of books and tried all the examples, as practice, and am building on a number of years of software development experience ( > 10 years) in other object oriented languages including C++, just not Java, but I'm picking it up pretty quickly.
I've also downloaded, what I believe is, the version of the source code running on my 'Droid running repo / git, and I've been digging into the FRG83G packages/apps/AccountsAndSyncSettings/src/com/android/settings code.
Now. I want to write a little app that will let me know when a Sync fails. The scratch that I'm trying to itch is that after I've made a large amount of changes using the GMail contact interface (for example), and the 'Droid fails to sync them (too many deletes perhaps?). So when a sync consistently fails, I wa开发者_如何学Cnt to display a notification bar icon to let the me know about this sync failure. Without an app like this, the first indication that it's been failing is when I notice missing contact information perhaps 2-3 days later.
So, logic would seem to indicate that my little app needs to be a SyncStatusObserver to be informed when a sync action changes status, then obtain SyncStatusInfo on that sync and note which sync failed and when. From what I can gather, this means implementing a SyncStatusObserver and connect it to the broadcast with call to ContentResolver.addStatusChangeListener. I've implemented this, and I do see the notification messages.
I believe I understand the object model in that an Account Type has zero to many account authorities, and that each account authority denotes the type of data that is being synced (contacts vs. calendar, etc.).
The SyncStatusObserver's single method, onStatusChanged( final int which ), has the 'int which' parameter, that appears to be trying to indicate which account type or which account authority just changed it's sync status. I've written and connected this, and am receiving these method invocations, as one would expect, when a type of data has synced. I've observed this in the Eclipse debugger logging window while my app is executing.
My question is how to do you related the single int which parameter value back to an account type, and / or an account authority? I'd like to call SyncInfo getCurrentSync() and record the account, the authority and the startTime. (Why start time? Don't we really want end time, and end status?)
Searching here on stackoverflow, I find in posting How does one listen for progress from Android SyncAdapter? that the SyncStatusObserver is pretty useless as it doesn't communicate very much useful information with a single integer parameter. Oh. OK.
I guess there's another way to look at this question is this: On the HTC Incredible, when you are at the home screen and you select Menu -> Settings -> Accounts & sync -> Google (an account listed), the user interface shows the last time that each account type of the GMail account was successfully synced. Where is the code that gets this information, as this the same information that I'm after, and I want to get this information after each SyncStatusObserver's onStatusChanged method invocation.
In posting Syncadapter last update date Which basically states that the last sync date / time is not exposed by the current Droid code.
Is there any other way to obtain the last successful sync date / time for each of the SyncAdators? I really want to scratch my itch (so to speak).
private final SyncStatusObserver mSyncStatusObserver = new SyncStatusObserver() {
@Override
public void onStatusChanged(int which) {
runOnUiThread(new Runnable() {
@Override
public void run() {
String accountName = AccountUtils.getChosenAccountName(HomeActivity.this);
if (TextUtils.isEmpty(accountName)) {
setRefreshActionButtonState(false);
return;
}
Account account = new Account(accountName, GoogleAccountManager.ACCOUNT_TYPE);
boolean syncActive = ContentResolver.isSyncActive(
account, ScheduleContract.CONTENT_AUTHORITY);
boolean syncPending = ContentResolver.isSyncPending(
account, ScheduleContract.CONTENT_AUTHORITY);
setRefreshActionButtonState(syncActive || syncPending);
}
});
}
};
精彩评论