检查同步的Android应用程序中启用 [英] Check if Sync is Enabled within Android App
问题描述
有没有一种方法来检查,编程在我的Android应用程序,无论是在设置>帐户与同步>数据及功放特定设置;同步或不启用?
Is there a way to check, programmatically within my Android app, whether a particular setting under Settings > Accounts and Sync > Data & Synchronization is enabled or not?
有没有一种方法来检查是否已启用一般的同步设置?
Is there a way to check if the general sync settings are enabled?
谢谢!
如果它有助于了解为什么,我目前我自己的滚动同步功能(不使用SyncAdapter)。不过,如果可能,我想有所列数据与放大器在我的同步服务;同步。现在,我打算砍,什么也不做一个虚拟同步的服务,并有我的应用程序的同步服务查询伪同步服务是否启用。这将告诉我是否同步与否。
If it helps to know "why," I'm currently rolling my own sync functionality (not using SyncAdapter). However, if possible I'd like to have my sync service listed under Data & Synchronization. Right now I'm planning to hack a dummy sync service that does nothing and have my app's sync service query whether or not the dummy sync service is enabled. That will tell me whether to sync or not.
推荐答案
您可以检查同步是否启用或不低于code和<一的帮助href="http://developer.android.com/reference/android/content/ContentResolver.html#isSyncActive%28android.accounts.Account,%20java.lang.String%29">this 文件
You can check whether sync is enable or not with the help of below code and this Document
AccountManager am = AccountManager.get(YourActivity.this);
Account account = am.getAccountsByType(Const.ACCOUNT_TYPE)[0];
if(ContentResolver.isSyncActive(account, DataProvider.AUTHORITY){
// sync is enable
}
您还可以设置启用/与这个的帮助下禁用编程 ContentResolver.setSyncAutomatically
和 ContentResolver.setMasterSyncAutomatically
You can also set enable/disable programmatically with the help of this ContentResolver.setSyncAutomatically
and ContentResolver.setMasterSyncAutomatically
更新
如果目前还同步操作对等待列表中指定的帐户或授权,或正在积极处理。
isSyncActive returns true if there is currently a sync operation for the given account or authority in the pending list, or actively being processed.
这篇关于检查同步的Android应用程序中启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!