开发者

How to change sync settings through Android API?

开发者 https://www.devze.com 2023-01-03 16:55 出处:网络
Is there a way to change the syn开发者_StackOverflow社区c settings of a Gmail account programmatically with an Android app?For instance, I\'d like to enable/disable syncing of a Gmail account from my

Is there a way to change the syn开发者_StackOverflow社区c settings of a Gmail account programmatically with an Android app? For instance, I'd like to enable/disable syncing of a Gmail account from my app, without the user having to do anything.

I took a look at AccountManager, but that doesn't seem to be the right place to look.


You can change it through the API using ContentResolver.setSyncAutomatically(Account account, String authority, boolean sync). You need to get a handle to the account in question (usually through the AccountManager class...) and you'll need to lookup the content authority string. The latter you can get from android.Provider.xxxContract (ContactsContract for example...)


I can tell you:

  • Generally, sync is controlled via the BACKGROUND_DATA setting in Settings.Secure, which cannot be modified by applications
  • The Gmail application is not part of the SDK and so exposes no APIs
0

精彩评论

暂无评论...
验证码 换一张
取 消