Search code examples
androideclipseandroid-syncadapter

Android developers syncadapter tutorial out of date?


Is the android developers syncadapter tutorial out of date.

Because i was trying to implement a sync adapter in my application that syncs data to a server. But when implementing the following part i get eclipse errors.

Implementing the syncadapter that syncs when network is available:

Android developers tutorial:

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);
        ...
    }
    ...
}

What happens in my code: Have the following variables

// 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;

and in oncreate i do this:

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);

I get an error in eclipse in the mResolver.setSyncAutomatically(ACCOUNT, AUTHORITY, true); it says the following:

The method setSyncAutomatically(Account, String, boolean) in the type ContentResolver is not applicable for the arguments (String, String, boolean)

So i am stuck here the tutorial tells me to do this but the ACCOUNT needs to be the type Account and not string. Is the tutorial out of date?


Solution

  • Use:

    Account newAccount = new Account("AccountName","com.example.accountType"); This can be used to access the account you already created.