У меня есть 3 метода, чтобы попытаться выполнить sh, но никогда их не проверял:
Решение 1 - setSyncAutomatics:
Account[] accounts = AccountManager.get(this).getAccountsByType(theAccountType);
for (Account account : accounts) {
Log.d(TAG, "got " + account.type + " / " + account.name);
ContentResolver.setSyncAutomatically(account,ContactsContract.AUTHORITY,false); // disable auto-syncing on that sync-adapter
ContentResolver.setIsSyncable (счета, ContactsContract.AUTHORITY, ложь); // отключаем periodi c syn c также}
Решение 2 - removeAccountExplicitly:
I думаю , что, в зависимости от вашего целевой API Android может вызвать исключение, если вы пытаетесь отключить адаптер syn c, который не принадлежит вашему собственному приложению (то есть подписан с использованием другого сертификата). Однако стоит попробовать.
Account[] accounts = AccountManager.get(this).getAccountsByType(theAccountType);
for (Account account : accounts) {
Log.d(TAG, "got " + account.type + " / " + account.name);
AccountManager.removeAccountExplicitly(account); // completely removing the account, not just disabling sync... beware.
}
Решение 3 - запустить экран настроек syncadapter:
Второй лучший вариант, который у вас есть, это запуск экран настроек c, позволяющий пользователю быстро отключить syn c одним щелчком мыши:
final SyncAdapterType[] syncs = ContentResolver.getSyncAdapterTypes();
for (SyncAdapterType sync : syncs) {
Log.d(TAG, "found SyncAdapter: " + sync.accountType);
if (theAccountType.equals(sync.accountType)) {
Log.d(TAG, "found it: " + sync);
String activityStr = sync.getSettingsActivity();
Intent intent = new Intent(Intent.ACTION_VIEW, activityStr);
// launch the intent
}
}