2014-05-22 77 views
1

android開發人員syncadapter教程是否過期。Android開發者syncadapter教程過時了嗎?

因爲我試圖在我的應用程序中實現同步數據到服務器的同步適配器。但是當執行下面的部分時,我得到了eclipse錯誤。

實現當網絡可用的同步操作的syncadapter:

Android開發教程:

public class MainActivity extends FragmentActivity { 
    ... 
    // Constants 
    // Content provider authority 
    public static final String AUTHORITY = "com.example.android.datasync.provider"; 
    // Account 
    public static final String ACCOUNT = "default_account"; 
    // Global variables 
    // A content resolver for accessing the provider 
    ContentResolver mResolver; 
    ... 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     ... 
     // Get the content resolver for your app 
     mResolver = getContentResolver(); 
     // Turn on automatic syncing for the default account and authority 
     mResolver.setSyncAutomatically(ACCOUNT, AUTHORITY, true); 
     ... 
    } 
    ... 
} 

在我的代碼會發生什麼: 有以下變量

// Constants 
// The authority for the sync adapter's content provider 
public static final String AUTHORITY = "com.example.android.datasync.provider"; 
// An account type, in the form of a domain name 
public static final String ACCOUNT_TYPE = "example.com"; 
// The account name 
public static final String ACCOUNT = "dummyaccount"; 
// Instance fields 
Account mAccount; 
// Global variables 
// A content resolver for accessing the provider 
ContentResolver mResolver; 

,並在OnCreate我這樣做:

mAccount = CreateSyncAccount(this); 
// Get the content resolver for your app 
mResolver = getContentResolver(); 
// Turn on automatic syncing for the default account and authority 
mResolver.setSyncAutomatically(ACCOUNT, AUTHORITY, true); 

我在月食中得到一個錯誤mResolver.setSyncAutomatically(ACCOUNT,AUTHORITY,true);它說以下內容:

在類型ContentResolver的方法setSyncAutomatically(帳戶,字符串,布爾)不適用的參數(字符串,字符串,布爾)

,所以我堅持在這裏的教程告訴我這樣做,但ACCOUNT需要是Account類型而不是字符串。教程是否過時?

+1

記錄與谷歌的請求,以便他們可以更新教程,如果你認爲它已過時。這是最好的前進方向。 – ChuongPham

回答

0

用途:

帳戶newAccount =新帳戶( 「帳戶名」, 「com.example.accountType」);這可用於訪問您已創建的帳戶。

+0

我知道我可以使用mAccount變量來避免給我一個錯誤。我的問題是教程過時了嗎? – JoaoFilipeClementeMartins

+1

這是不是過時了,這是錯的。據我所知,從來沒有一個字符串參數 – Arno

0

setSyncAutomatically的第一個參數是一個Account對象,而不是String。你正在使用一個字符串。您需要使用AccountManager來獲取適當的帳戶並使用它。

+0

我知道,這不是我的問題,我的問題是爲什麼在教程中這是錯誤的?它應該使用mAccount權限?但他們不在那裏。 – JoaoFilipeClementeMartins