onPerformSync()方法没有被调用

时间:2016-02-02 17:10:25

标签: android android-syncadapter

我已经使用虚拟帐户实现了SyncAdapter,但是当我转到设置时 - >帐户 - > MyApp,Sync在那里关闭。我想让它在24小时内自动同步。我怎样才能做到这一点。

1 个答案:

答案 0 :(得分:0)

在创建虚拟帐户的位置,您必须启用同步并为其添加定期同步。像这样:

final String AUTHORITY = "com.example.yourapp.authority";
final int SYNCABLE = 1;
final long SYNC_FREQUENCY_IN_SECONDS = 24 * 60 * 60; // once a day
ContentResolver.setIsSyncable(account AUTHORITY, SYNCABLE);
ContentResolver.setSyncAutomatically(account, AUTHORITY, true);
ContentResolver.addPeriodicSync(account, AUTHORITY, Bundle.EMPTY, 
    SYNC_FREQUENCY_IN_SECONDS);
相关问题