问题描述
我想为要与服务器同步的内容实现 SyncAdapter.似乎要这样做,您需要为您在 SyncAdapter XML 属性文件中指定的权限注册一个 ContentProvider.
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 specify in the SyncAdapter XML property file.
由于我不希望手机的其余部分可以访问此内容,因此我尚未实现自己的 ContentProvider 并使用个人实现来存储此内容.
As I don't want this content to be accessible to the rest of the phone, I haven't implemented my own ContentProvider and used a personal implementation to store this content.
您知道是否可以在不提供 ContentProvider 的情况下使用 SyncAdapter 提供同步?
Do you know if it is possible to provide a synchronization using a SyncAdapter without providing a ContentProvider?
非常感谢.
推荐答案
在实现 SyncAdapter 时,您总是必须指定内容提供程序,但这并不是说它实际上必须执行任何操作.
You always have to specify a content provider when implementing a SyncAdapter, but that's not to say it actually has to do anything.
我编写了 SyncAdapters,用于创建帐户并与 Android 中的帐户与同步"框架集成,这些框架不一定将其内容存储在标准提供程序中.
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.
在您的 xml/syncadapter.xml 中:
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" />
在您的清单中:
<provider android:name="DummyProvider"
android:authorities="com.company.content"
android:syncable="true"
android:label="DummyProvider" />
然后添加一个除了存在之外没有任何用处的虚拟提供程序,DummyProvider.java:
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;
}
}
这篇关于没有 ContentProvider 的 SyncAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!