0

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?

  • 1
    Log a request with Google so they can update the tutorial if you believe it's out of date. It's the best way forward. – ChuongPham May 22 '14 at 14:47

3 Answers3

0

The first argument to setSyncAutomatically is an Account object, not a String. You are using a String. You need to use AccountManager to obtain the proper Account and use that.

Karakuri
  • 38,365
  • 12
  • 84
  • 104
0

Use:

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

Arno van Lieshout
  • 1,570
  • 1
  • 13
  • 19
0

The account parameter is from type Account. I have the full Android documentation on each of my devices and the BasicSyncAdapter (http://developer.android.com/downloads/samples/BasicSyncAdapter.zip) of google is compilable via AIDE, but at the points of a custom Authenticator and the SyncAdapter not everything is described as clear as possible. I hope this example could help you a bit: http://udinic.wordpress.com/2013/07/24/write-your-own-android-sync-adapter/

Patrick Leitermann
  • 2,144
  • 2
  • 13
  • 13