1

I created an account with the accountmanager from the mobile accounts section and added the app as an account. But I want the app to start session with that added account, I've seen that you have to perform the syncadapter to get this out. I added the service and the provider in the manifest, the service class and the class for the methods.

    <provider
        android:name="com.example.pargibay.androidphprpcxml.StubProvider"
        android:authorities="com.example.pargibay.androidphprpcxml.provider"
        android:exported="false" />

    <service
        android:name=".SyncAdapterService"
        android:exported="true">
        <intent-filter>
            <action android:name="android.content.SyncAdapter" />
        </intent-filter>

        <meta-data
            android:name="android.content.SyncAdapter"
            android:resource="@xml/sync_adapter" />
    </service>

The class Service:

public class SyncAdapterService extends Service {

private static SyncAdapter sSyncAdapter = null;
private static final Object sSyncAdapterLock = new Object();

@Override
public void onCreate() {
    Log.d("SyncStarted","SyncService started");
    synchronized (sSyncAdapterLock) {
        if (sSyncAdapter == null) {
            try {
                sSyncAdapter = new SyncAdapter(getApplicationContext(), true);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            Log.d("SyncStoped","SyncService stoped");
        }
    }
}

@Nullable
@Override
public IBinder onBind(Intent intent) {
    return sSyncAdapter.getSyncAdapterBinder();
}
}

The class methods sync adapter:

public class SyncAdapter extends AbstractThreadedSyncAdapter {


public SyncAdapter(Context context, boolean autoInitialize) throws MalformedURLException {
    super(context, autoInitialize);
}

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
    }
}

I wanted to know how I can synchronize automatically, the account that I created from the accountmanager. I followed this tutorial to create the account from the accounmanager.

EDIT:

I just saw this post and I wanted it to come out this way when I see the accounts added in the application and what I can give you I want to synchronize

SyncAdapter android:userVisible attribute not working

Pedro
  • 21
  • 3

0 Answers0