【问题标题】:"Sync is Off" showing after running the Sync Adapter On Demand using ContentResolver.requestSync() function使用 ContentResolver.requestSync() 函数运行按需同步适配器后显示“同步已关闭”
【发布时间】:2015-08-26 16:35:37
【问题描述】:

我正在尝试实现联系人同步适配器。当我从相应帐户下提供的同步选项进行同步操作时,它工作正常。但是,当我尝试在按钮单击时调用requestSync() 第一次 时,SyncAdapter 实现的onPerformSync() 函数调用并成功执行,但仍显示 Sync is Off 在相应帐户下同步设置。

我的按需运行同步适配器的代码是:

Bundle settingsBundle = new Bundle();
                settingsBundle.putBoolean(
                        ContentResolver.SYNC_EXTRAS_MANUAL, true);
                settingsBundle.putBoolean(
                        ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
                /*
                 * Request the sync for the default account, authority, and
                 * manual sync settings
                 */


                ContentResolver.requestSync(mAccount, AUTHORITY, settingsBundle);

所以请指导我,有什么方法可以在运行 Sync Adapter On Demand 后打开 Sync Setting。

【问题讨论】:

    标签: android android-contacts android-syncadapter


    【解决方案1】:

    为了实现我的目标,我需要在调用requestSync(----) 之前设置以下属性:

    ContentResolver.setSyncAutomatically(mAccount, getString(R.string.content_provider_authority), true);
    

    【讨论】:

    • 有点对应:我预计调用 ContentResolver.addPeriodicSync(account, authority, bundle, internalSecs) 会将我的同步适配器设置为打开,但事实并非如此。调用 setSyncAutomatically 也解决了我的问题。
    猜你喜欢
    • 2016-02-11
    • 1970-01-01
    • 1970-01-01
    • 2021-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多