packages/apps/Gallery2
修订版 | 515cfec73e24176768aa9e5bbf9b3f5f205fad7b (tree) |
---|---|
时间 | 2010-01-26 04:55:57 |
作者 | Venkat Krishnaraj <venkatkrishnaraj@venk...> |
Commiter | Chih-Chung Chang |
Fix for checking to see if an account has picasa enabled before setting it explicitly to on by default
@@ -1,6 +1,11 @@ | ||
1 | 1 | package com.cooliris.picasa; |
2 | 2 | |
3 | +import java.io.IOException; | |
4 | + | |
3 | 5 | import android.accounts.Account; |
6 | +import android.accounts.AccountManager; | |
7 | +import android.accounts.AuthenticatorException; | |
8 | +import android.accounts.OperationCanceledException; | |
4 | 9 | import android.content.AbstractThreadedSyncAdapter; |
5 | 10 | import android.content.BroadcastReceiver; |
6 | 11 | import android.content.ContentProviderClient; |
@@ -23,8 +28,30 @@ public class PicasaSyncAdapter extends AbstractThreadedSyncAdapter { | ||
23 | 28 | public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient providerClient, |
24 | 29 | SyncResult syncResult) { |
25 | 30 | if (extras.getBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, false)) { |
26 | - ContentResolver.setIsSyncable(account, authority, 1); | |
27 | - ContentResolver.setSyncAutomatically(account, authority, true); | |
31 | + try { | |
32 | + Account[] picasaAccounts = AccountManager.get(getContext()) | |
33 | + .getAccountsByTypeAndFeatures( | |
34 | + PicasaService.ACCOUNT_TYPE, | |
35 | + new String[] { PicasaService.FEATURE_SERVICE_NAME }, | |
36 | + null /* callback */, null /* handler */).getResult(); | |
37 | + boolean isPicasaAccount = false; | |
38 | + for (Account picasaAccount : picasaAccounts) { | |
39 | + if (account.equals(picasaAccount)) { | |
40 | + isPicasaAccount = true; | |
41 | + break; | |
42 | + } | |
43 | + } | |
44 | + if (isPicasaAccount) { | |
45 | + ContentResolver.setIsSyncable(account, authority, 1); | |
46 | + ContentResolver.setSyncAutomatically(account, authority, true); | |
47 | + } | |
48 | + } catch (OperationCanceledException e) { | |
49 | + ; | |
50 | + } catch (IOException e) { | |
51 | + ; | |
52 | + } catch (AuthenticatorException e) { | |
53 | + ; | |
54 | + } | |
28 | 55 | return; |
29 | 56 | } |
30 | 57 | PicasaService.performSync(mContext, account, extras, syncResult); |