本文整理汇总了Java中android.content.ContentResolver.setMasterSyncAutomatically方法的典型用法代码示例。如果您正苦于以下问题:Java ContentResolver.setMasterSyncAutomatically方法的具体用法?Java ContentResolver.setMasterSyncAutomatically怎么用?Java ContentResolver.setMasterSyncAutomatically使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ContentResolver
的用法示例。
在下文中一共展示了ContentResolver.setMasterSyncAutomatically方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setSyncActivated
import android.content.ContentResolver; //导入方法依赖的package包/类
public void setSyncActivated(boolean enabled) {
ContentResolver.setMasterSyncAutomatically(enabled);
if (enabled) {
SyncAdapterType[] types = ContentResolver.getSyncAdapterTypes();
AccountManager accmgr = AccountManager.get(mContext);
for (SyncAdapterType type : types) {
Account[] accounts = accmgr.getAccountsByType(type.accountType);
for (Account account : accounts) {
if (Constants.DEBUG) {
Log.d(TAG, "synching account, name:" + account.name + ", type: " + account.type);
}
enabled = ContentResolver.getSyncAutomatically(account, type.authority);
if (enabled) {
// trigger update for next account
ContentResolver.requestSync(account, type.authority, new Bundle());
}
}
}
}
}
示例2: onHandleIntent
import android.content.ContentResolver; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
if (intent.getAction().equals(ACTION_TOGGLE_SYNC)) {
final boolean newState;
if (intent.hasExtra(AShortcut.EXTRA_ENABLE)) {
newState = intent.getBooleanExtra(AShortcut.EXTRA_ENABLE, false);
} else {
newState = !ContentResolver.getMasterSyncAutomatically();
}
ContentResolver.setMasterSyncAutomatically(newState);
if (intent.getBooleanExtra(AShortcut.EXTRA_SHOW_TOAST, false)) {
showToast(newState ?
R.string.quick_settings_sync_on :
R.string.quick_settings_sync_off);
}
} else if (intent.getAction().equals(ACTION_GET_SYNC_STATUS)) {
boolean syncStatus = ContentResolver.getMasterSyncAutomatically();
ResultReceiver receiver = intent.getParcelableExtra("receiver");
Bundle data = new Bundle();
data.putBoolean(KEY_SYNC_STATUS, syncStatus);
receiver.send(RESULT_SYNC_STATUS, data);
} else if (intent.getAction().equals(QuietHoursActivity.ACTION_SET_QUIET_HOURS_MODE)) {
QuietHours.Mode qhMode = QuietHoursActivity.setQuietHoursMode(this, intent.getStringExtra(
QuietHoursActivity.EXTRA_QH_MODE));
if (qhMode != null && intent.getBooleanExtra(AShortcut.EXTRA_SHOW_TOAST, false)) {
showToast(QuietHoursActivity.getToastResIdFromMode(qhMode));
}
}
}