2013-09-05 64 views
0

我的應用程序有2種自動同步模式(所有網絡/只是WiFi)。Android如何在帳戶和設置中開啓同步功能

我想聽用戶何時在Android設置(不是我的應用程序設置)中打開自動同步,然後相應地設置我的自動模式。

如何在用戶打開Android設置中的同步時收聽?

回答

0

以下是存儲該複選框值的內容提供者。

@覆蓋

public boolean [More ...] onPreferenceTreeClick(PreferenceScreen preferences, Preference preference) { 

    if (preference instanceof SyncStateCheckBoxPreference) { 

     SyncStateCheckBoxPreference syncPref = (SyncStateCheckBoxPreference) preference; 

     String authority = syncPref.getAuthority(); 

     Account account = syncPref.getAccount(); 

     boolean syncAutomatically = ContentResolver.getSyncAutomatically(account, authority); 

     if (syncPref.isOneTimeSyncMode()) { 

      requestOrCancelSync(account, authority, true); 

     } else { 

      boolean syncOn = syncPref.isChecked(); 

      boolean oldSyncState = syncAutomatically; 

      if (syncOn != oldSyncState) { 

       // if we're enabling sync, this will request a sync as well 

       ContentResolver.setSyncAutomatically(account, authority, syncOn); 

       // if the master sync switch is off, the request above will 

       // get dropped. when the user clicks on this toggle, 

       // we want to force the sync, however. 

       if (!ContentResolver.getMasterSyncAutomatically() || !syncOn) { 

        requestOrCancelSync(account, authority, syncOn); 


       } 
      } 
     } 

這東西,你需要做一些額外的工作。設置始終將每個值保存到共享首選項。您需要從共享首選項中找到該值併爲該共享首選項更改偵聽器註冊。我不知道是否可以聽取該同步複選框。

這裏是你找到那個複選框或切換首選項的地方,其中保存了值。 分析FirstSecond鏈接。

還有一點需要注意的是,設置代碼在此表中保存了一些值。

First table

Second table

Third table

相關問題