Android如何以编程方式启用/禁用自动同步 [英] Android how to enable/disable auto sync programmatically

查看:28
本文介绍了Android如何以编程方式启用/禁用自动同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何以编程方式打开和关闭自动同步.

I need to know how to toggle auto sync on and off programmatically.

推荐答案

我想你在找

ContentResolver.setMasterSyncAutomatically(<boolean>);

文档是怎么说的:

设置适用于所有提供程序的主自动同步设置和帐户.如果这是错误的,那么每个提供者的自动同步设置被忽略.

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.

此方法需要调用者持有权限WRITE_SYNC_SETTINGS.

This method requires the caller to hold the permission WRITE_SYNC_SETTINGS.

所以不要忘记在 manifest.xml 中添加权限:

So don't forget to add permission into manifest.xml:

<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />

这应该禁用/启用所有同步.

This should disable / enable all the syncs.

@Sajmon:我更新了这个我认为非常有用的答案(我在我的个人项目中使用它).

@Sajmon: I updated this i think very useful answer (i'm using this in my personal project).

这篇关于Android如何以编程方式启用/禁用自动同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆