2014-09-11 70 views
6

我正在嘗試使用同步適配器執行週期同步。它可以手動同步,但不會定期。這是我從logcat的執行週期性同步時出錯

Could not find class 'android.content.SyncRequest$Builder', referenced from method 
com.example.user.sunshine.sync.SunshineSyncAdapter.configurePeriodicSync 

下面得到的唯一的事情是我的代碼:

public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) { 

    Account account = getSyncAccount(context); 
    String authority = context.getString(R.string.content_authority); 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 
     SyncRequest request = new SyncRequest.Builder(). 
       syncPeriodic(syncInterval, flexTime). 
       setSyncAdapter(account, authority).build(); 
     ContentResolver.requestSync(request); 
    } else { 
     ContentResolver.addPeriodicSync(account, 
       authority, new Bundle(), syncInterval); 
    } 
} 

有誰知道爲什麼會這樣,我應該如何去有關解決呢?

回答

-1

如果您在未運行KitKat及更高版本的設備上進行測試,則會顯示此錯誤。我敢打賭,它在Kitkat和上面沒有問題,因爲適當的android類將被編譯到apk中。

我建議你不要擔心,如果你對下級設備的測試,因爲你的代碼的這一部分,:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 
     SyncRequest request = new SyncRequest.Builder(). 
       syncPeriodic(syncInterval, flexTime). 
       setSyncAdapter(account, authority).build(); 
     ContentResolver.requestSync(request); 
    } else { 
     ContentResolver.addPeriodicSync(account, 
       authority, new Bundle(), syncInterval); 
    } 

也可嘗試檢查導出按鈕爲Android 4.4 *在建庫。