Syncadapter Without a Contentprovider

SyncAdapter without a ContentProvider

You always have to specify a content provider when implementing a SyncAdapter, but that's not to say it actually has to do anything.

I've written SyncAdapters that create accounts and integrate with the "Accounts & sync" framework in Android that don't necessarily store their content in a standard provider.

In your xml/syncadapter.xml:

<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android" 
android:accountType="com.company.app"
android:contentAuthority="com.company.content"
android:supportsUploading="false" />

In your manifest:

<provider android:name="DummyProvider"
android:authorities="com.company.content"
android:syncable="true"
android:label="DummyProvider" />

And then add a dummy provider that doesn't do anything useful except exist, DummyProvider.java:

public class DummyProvider extends ContentProvider {

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
return 0;
}

@Override
public String getType(Uri uri) {
return null;
}

@Override
public Uri insert(Uri uri, ContentValues values) {
return null;
}

@Override
public boolean onCreate() {
return false;
}

@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
return null;
}

@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
return 0;
}
}

Sync adapter in android without content provider and authentication account

No. To register a sync adapter in manifest file, you need to provide the content provider details also.

For using sync adapters, you need to have an Authenticator service. When your application account is added to the device accounts list, Sync option can be set on it. When the device sees that the application needs to be synced, first it will check the Authenticator's response. Once authenticator provides authToken, Sync service will use content provider and perform actions in sync adapter.

See : http://blog.udinic.com/2013/07/24/write-your-own-android-sync-adapter
and : http://blog.udinic.com/2013/04/24/write-your-own-android-authenticator/

I really found these links useful. I have implemented sync adapter using these links.

If you don't at all want to write a content provider , but need a sync adapter, you can create a content provider, and dont specify any functionality inside. It will just be a dummy provider.

See : SyncAdapter without a ContentProvider

Custom SyncAdapter without using ContentProvider

Short answer: No, it's not possible.

Long answer: The Android platform's model for sync is to link a user Account to a ContentProvider through a SyncAdapter. You can't set up the XML tags in AndroidManifest to be read by the Android platform without having set up all three.

Biased answer: You should never write an app with a local DB. ContentProvider is by far the way to go, for the reasons listed here.

SyncAdapter without ContentObserver

You don't need a ContentObserver to trigger a sync when using a SyncAdapter. Just make sure you set syncToNetwork to true when you call notifyChange (Uri uri, ContentObserver observer, boolean syncToNetwork).

Android will automatically call all SyncAdapters for this authority that have supportsUploading set to true and that are configured to sync automatically.

Sync Adapter without Account

I have created a contact sync adapter where I don't have a account authorization and or configuration screens. It wasn't that hard. I don't think having to deal with the Android Account stuff was that much of a deal.

Quote from your tutorial link:

The bad news is that there is no
“stock” functionality to give you an
easy way to provide an Account to the
system. However, in the same Sync
Adapter Example that comes with the
SDK there is a lot of code you can
borrow to give you Account
functionality. Unless you desire a
custom credentials screen, you can
heist all the code in the
com.example.android.samplesync.authenticator
package with only a few minor changes.

So it's basically just a copy and paste from the example, that's pretty much what I did and it worked fine.

I don't know for sure but all the adapters that don't have "Remove Account" seems to be built-in ROM adapters on all the devices I've looked at. I'm not sure you have to worried about it.

How do I implement an Account on Android without a SyncAdapter

I sort of solved my own problem: you cannot return null from the onBind method of your service - you must return the IBinder of an AbstractThreadedSyncAdapter.

This has the undesired effect of adding an entry into the Data and Synchronization section of the account settings page, even though my implementation of AbstractThreadedSyncAdapter does nothing; I was hoping to avoid this.

To summarize, in order to make use of the accounts system in Android you must:

  • Implement a service that has an IntentFilter for android.content.SyncAdapter.
  • This service must return the IBinder of an AbstractThreadedSyncAdapter implementation from it's onBind method.
  • This then necessitates that you have a ContentProvider (can just be a stub implementation) that is referred to as the contentAuthority in your SyncAdapter XML file.
  • This has the down-side that your ContentProvider is listed under the Data and Synchronization header on your account settings page.


Related Topics



Leave a reply



Submit