【问题标题】:Toggle on auto-sync progarammatically in Android在 Android 中以编程方式打开自动同步
【发布时间】:2013-07-05 13:14:59
【问题描述】:

可能是这个question 大约 2-4 年前被问到。仍然不满意。我的问题是:“如何以编程方式打开/关闭自动同步”。我不希望任何特定数据同步。只想要知道是否可以通过编程方式启用或禁用自动同步?如果可能,那么如何?谁能给我一个例子?

在 Android 屏幕上显示如下:

ContentResolver.setSyncAutomatically(account, authority, true); 在自动同步中有什么用?

提前致谢。

【问题讨论】:

    标签: android


    【解决方案1】:

    我猜你说的是 gmail 自动同步电子邮件吧?一种方法是 setMasterSyncAutomatically() (ContentResolver),适用于所有帐户(和提供者)。如果您将此设置为 off/false,您可以禁用所有同步。

    这是我们从 android documentation 得到的。

    public static void setMasterSyncAutomatically (boolean sync)
    
    Added in API level 5
    Sets the master auto-sync setting that applies to all the providers and accounts. If this is false then the per-provider auto-sync setting is ignored.
    
    This method requires the caller to hold the permission WRITE_SYNC_SETTINGS.
    
    Parameters
    sync    the master auto-sync setting that applies to all the providers and accounts
    

    【讨论】:

    • ContentResolver.setMasterSyncAutomatically(true);是这样的吗?..所以我只需要在我的类中添加这一行吗?
    • 坦率地说,以编程方式更改设置是一种粗鲁的做法,您应该在这样做之前征得用户的许可。
    • 继续尝试,它应该可以工作。要对其进行测试,请确保在运行应用之前关闭所有同步。
    • 没用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多