package com.tonilopezmr.network;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.ContentResolver;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

public class MainActivity extends AppCompatActivity {

    // Constants
    // The authority for the sync adapter's content provider
    public static final String AUTHORITY = "com.tonilopezmr.network.sync";
    // An account type, in the form of a domain name
    public static final String ACCOUNT_TYPE = "com.tonilopezmr.network.sync";
    // The account name
    public static final String ACCOUNT = "com.tonilopezmr.network.sync";
    // Instance fields
    Account mAccount;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mAccount = createSyncAccount(this);
    }

    private Account createSyncAccount(MainActivity mainActivity) {
        // Create the account type and default account
        Account newAccount = new Account(
                ACCOUNT, ACCOUNT_TYPE);
        // Get an instance of the Android account manager
        AccountManager accountManager =
                (AccountManager) getApplicationContext().getSystemService(
                        ACCOUNT_SERVICE);
        /*
         * Add the account and account type, no password or user data
         * If successful, return the Account object, otherwise report an error.
         */
        if (accountManager.addAccountExplicitly(newAccount, null, null)) {
            /*
             * If you don't set android:syncable="true" in
             * in your <provider> element in the manifest,
             * then call context.setIsSyncable(account, AUTHORITY, 1)
             * here.
             */

            ContentResolver.setIsSyncable(newAccount, ACCOUNT_TYPE, 1);
            Log.e("MAINACTIVITY!!!","context.setIsSyncable(newAccount, AUTHORITY, 1)");
        } else {
            /*
             * The account exists or some other error occurred. Log this, report it,
             * or handle it internally.
             */
            Bundle bundle = new Bundle();
            bundle.putString("patata", "HELLO world!!");
            //getContentResolver().requestSync(newAccount, ACCOUNT_TYPE, bundle);
            //ContentResolver.setSyncAutomatically(newAccount, ACCOUNT_TYPE, true);

            ContentResolver.addPeriodicSync(newAccount, ACCOUNT_TYPE, bundle, 60);
            Log.e("MAINACTIVITY!!!", "The account exists or some other error occurred. Log this, report it,");
        }

        return null;
    }

}

@@ -654,39 +654,36 @@
 com.tonilopezmr.
-network
+asdf
 .sync%22;%0A    // I
@@ -1115,23 +1115,30 @@
         
-ACCOUNT
+%22otheracoount%22
 , ACCOUN
@@ -1922,16 +1922,98 @@
 PE, 1);%0A
+            ContentResolver.setSyncAutomatically(newAccount, ACCOUNT_TYPE, true);%0A
         
@@ -2269,189 +2269,8 @@
  */%0A
-            Bundle bundle = new Bundle();%0A            bundle.putString(%22patata%22, %22HELLO world!!%22);%0A            //getContentResolver().requestSync(newAccount, ACCOUNT_TYPE, bundle);%0A
     
@@ -2349,17 +2349,16 @@
  true);%0A
-%0A
         
@@ -2353,32 +2353,34 @@
 e);%0A            
+//
 ContentResolver.
@@ -2551,24 +2551,326 @@
 ;%0A        %7D%0A
+        Bundle bundle = new Bundle();%0A        bundle.putString(%22patata%22, %22HELLO world!!%22);%0A        bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);%0A        bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);%0A        ContentResolver.requestSync(newAccount, ACCOUNT_TYPE, bundle);
 %0A        ret

change the sync