作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
下面是更新后的代码
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*60*1000 = 60000 = 1 分钟,
关于java - 如何为同步适配器设置 15 分钟的同步间隔。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44384916/
我是一名优秀的程序员,十分优秀!