Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android如何收听帐户和设置中打开的同步_Android_Settings_Sync - Fatal编程技术网

Android如何收听帐户和设置中打开的同步

Android如何收听帐户和设置中打开的同步,android,settings,sync,Android,Settings,Sync,我的应用程序有两种自动同步模式(所有网络/仅WiFi) 我想监听用户在Android设置(不是我的应用程序设置)中打开自动同步的时间,然后相应地设置我的自动模式 当用户在安卓设置中打开同步时,我如何监听?这里是存储该复选框值的内容提供商 @凌驾 public boolean [More ...] onPreferenceTreeClick(PreferenceScreen preferences, Preference preference) { if (preference ins

我的应用程序有两种自动同步模式(所有网络/仅WiFi)

我想监听用户在Android设置(不是我的应用程序设置)中打开自动同步的时间,然后相应地设置我的自动模式


当用户在安卓设置中打开同步时,我如何监听?

这里是存储该复选框值的内容提供商

@凌驾

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);


                }
            }
        }
这是你需要做一些额外工作的地方。设置始终将每个值保存到共享首选项。您需要从共享首选项中找到该值,并注册该共享首选项更改侦听器。我不知道是否可以监听同步复选框

这是一个链接,您可以在其中找到保存值的复选框或开关首选项。 分析链接

还有一点需要注意的是,设置代码在此表中保存了一些值