gpt4 book ai didi

java - 如何为同步适配器设置 15 分钟的同步间隔。?

转载 作者:行者123 更新时间:2023-11-30 00:30:57 26 4
gpt4 key购买 nike

下面是更新后的代码

public class MainActivityNew extends AppCompatActivity  {

private static final String Tag = "MainActivity";
// Instance fields
Account mAccount;

public static final long SECONDS_PER_MINUTE = 60L;
public static final long SYNC_INTERVAL_IN_MINUTES = 15L;
public static final long SYNC_INTERVAL =
SYNC_INTERVAL_IN_MINUTES *
SECONDS_PER_MINUTE;

private static final int NOTIFICATION_EX = 1;

ContentResolver resolver;


@Override
protected void onCreate(Bundle savedInstanceState) {
// Create the dummy account
mAccount = CreateSyncAccount(this);
resolver = getContentResolver();
resolver.setIsSyncable(mAccount, CommonUtilities.AUTHORITY, 1);
resolver.setSyncAutomatically(mAccount, CommonUtilities.AUTHORITY, true);
resolver.addPeriodicSync(
mAccount,
CommonUtilities.AUTHORITY,
Bundle.EMPTY,
SYNC_INTERVAL);}

public static Account CreateSyncAccount(Context context) {
// Create the mAccount call_type and default mAccount
Account newAccount = new Account(
ACCOUNT, ACCOUNT_TYPE);
// Get an instance of the Android mAccount manager
AccountManager accountManager =
(AccountManager) context.getSystemService(
ACCOUNT_SERVICE);
/*
* Add the mAccount and mAccount call_type, no password or user data
* If successful, return the Account object, otherwise report an error.
*/
if (accountManager.addAccountExplicitly(newAccount, null, null)) {
/*
* If you don't set android:syncable="true" in
* in your <provider> element in the manifest,
* then call context.setIsSyncable(mAccount, AUTHORITY, 1)
* here.
*/
ContentResolver.setIsSyncable(newAccount, AUTHORITY, 1);
ContentResolver.setMasterSyncAutomatically(true);
ContentResolver.setSyncAutomatically(newAccount, AUTHORITY, true);
} else {
/*
* The mAccount exists or some other error occurred. Log this, report it,
* or handle it internally.
*/
Log.d(Tag, "Error occured in creating mAccount");
}
return newAccount;
}

而且我还发送同步间隔时间,如 1*60*1000

  1. 如何为 Sync Adapter 设置 15 分钟的同步间隔?
  2. 1*60*1000L 和 1*60*1000 有什么区别?

最佳答案

1*60*1000 = 60000 = 1 分钟,

  1. 使用 15*60*1000 将同步间隔设置为 15 分钟。
  2. 1*60*1000L 返回 long,而 1*60*1000 返回 int(不适用于大数)

关于java - 如何为同步适配器设置 15 分钟的同步间隔。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44384916/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com