Android how to enable/disable auto sync programmatically(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如何以编程方式启用/禁用自动同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android如何以编程方式启用/禁用自动同步


- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01