SyncAdapter without a ContentProvider

前端 未结 2 1348
太阳男子
太阳男子 2020-11-30 23:13

I want to implement a SyncAdapter for a content I want to synchronize with a server. It seems that to do so, you need a ContentProvider registered for the authority you spec

2条回答
  •  执念已碎
    2020-11-30 23:51

    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:

    
    

    In your manifest:

       
    

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

提交回复
热议问题