Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何为同步适配器设置15分钟的同步间隔。?_Java_Android - Fatal编程技术网

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

Java 如何为同步适配器设置15分钟的同步间隔。?,java,android,Java,Android,下面是更新的代码 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 lon

下面是更新的代码

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;
    }
public class main活动new扩展appcompative活动{
私有静态最终字符串Tag=“MainActivity”;
//实例字段
账户mAccount;
公共静态最终长秒每分钟=60L;
公共静态最终长同步间隔(单位:分钟)=15L;
公共静态最终长同步间隔=
同步间隔(分钟)*
秒每分钟;
私有静态最终整数通知_EX=1;
内容解析器;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//创建虚拟帐户
mAccount=CreateSyncAccount(此);
解析程序=getContentResolver();
resolver.setIsSyncable(mAccount,CommonUtilities.AUTHORITY,1);
解析程序自动设置同步(mAccount,CommonUtilities.AUTHORITY,true);
resolver.addPeriodicSync(
麦考特,
公共事业机构,
Bundle.EMPTY,
同步_间隔);}
公共静态帐户CreateSyncAccount(上下文){
//创建mAccount调用类型和默认mAccount
帐户newAccount=新帐户(
账户,账户类型);
//获取Android mAccount管理器的实例
会计经理会计经理=
(AccountManager)context.getSystemService(
账户服务);
/*
*添加mAccount和mAccount呼叫类型,无密码或用户数据
*如果成功,则返回Account对象,否则报告错误。
*/
if(accountManager.addaccountexplicified(newAccount,null,null)){
/*
*如果未在中设置android:syncable=“true”
*在清单中的元素中,
*然后调用context.setIsSyncable(mAccount,AUTHORITY,1)
*在这里。
*/
ContentResolver.setIsSyncable(newAccount,AUTHORITY,1);
ContentResolver.setMasterSyncAutomatically(true);
ContentResolver.setsyncutomatically(newAccount,AUTHORITY,true);
}否则{
/*
*mAccount已存在或出现其他错误。请记录、报告此错误,
*或者内部处理。
*/
Log.d(标记“创建mAccount时出错”);
}
返回新帐户;
}
我还发送同步间隔时间,如1*60*1000

  • 如何为同步适配器设置15分钟的同步间隔
  • 1*60*1000L和1*60*1000有什么区别

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

  • 使用15*60*1000将同步间隔设置为15分钟
  • 1*60*1000L返回一个long,其中1*60*1000返回一个int(不适合大数字)

  • long SECONDS\u PER\u MINUTE=60L;long SYNC\u INTERVAL\u IN\u MINUTES=15L;long SYNC\u INTERVAL=SYNC\u INTERVAL\u IN\u MINUTES*SECONDS\u PER\u MINUTE;
    查看文档:不工作,它再次以1分钟的时间间隔同步。奇怪,请尝试使用900000L作为同步间隔。测试它现在,它对我有效。让我们一起来。