【发布时间】:2012-08-02 09:04:47
【问题描述】:
我正在开发一个带有 ContentProvider 的应用程序来提供一些内部文件(二进制文件)。当我将它部署在三星 Galaxy S、SII 或任何其他设备上时,它运行良好,当我在 Galaxy Nexus 或 Nexus S 上试用时购买,它不起作用!
场景:
可以使用两个 URI 访问我的 ContentProvider。根据此 URI,提供者创建 DataCursor(扩展 CrossProcessCursor)或 ModelCursor(也扩展 CrossProcessCursos)。事实是,在 Nexus 系列中,我访问第一个游标 (DataCursor) 以检索标识符,它运行良好,但是在访问第二个游标时,尝试时总是抛出“OutOfBoundsException”
getBlob()
方法。
提供者
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
Cursor cursor = null;
// If the third app requieres DATA (phrase id, phrase string and phrase name)
if(uri.toString().equalsIgnoreCase(ProviderConstants.DATA_URI.toString())) {
// Build the DataHelper and the customized cursor
DataHelper dataHelper = new DataHelper(getContext());
cursor = new DataCursor(dataHelper);
} else if(uri.toString().equalsIgnoreCase(ProviderConstants.MODEL_URI.toString())) {
// Let's take the model id from the selectionArgs...
if (selectionArgs != null && selectionArgs.length > 0) {
String modelId = selectionArgs[0];
// Get an instance to the persistent storage service...
File file = FileManager.getDirectory(getContext(), modelId);
FileSystemPersistentStorageService clientPersistentStorageService = new FileSystemPersistentStorageService(file);
cursor = new ModelCursor(clientPersistentStorageService);
} else {
Log.e("ContentProvider", "Query without model id on selectionArgs");
}
}
return cursor;
}
如果您需要一些代码或任何东西,请尽管索取!
非常感谢。
【问题讨论】:
-
对于初学者:1. 您的 Android 设备上有哪些确切的 SDK 版本? 2. 每个设备上的确切 SQLite 版本是什么 (
adb shell sqlite3 --version) 3. 代码在模拟器中是否正常工作? 4. 当您得到 OutOfBoundsException 时,完整的调用堆栈是什么? 5. ModelCursor 是如何实现的? 6. 你的数据库模型是什么? 7. 你如何使用你的内容提供者(代码)? -
1.从 2.3.3 到 4.0(广泛的设备) 2. 重要吗?我可以检查它们,但 ModelCursor 不会从 SQLite 中获取数据,而只是从内部文件 storage.3 中获取数据。 [待测试,谢谢]。 4.link。 5. 只需要
getBlob,其他需要link。 6.不需要数据库。 7.Cursor modelCursor = getContentResolver().query(Uri.parse("content://" + PROVIDER_NAME + "/model"), null, null, new String[] {modelId}, null);-modelCursor.getBlob(0); -
您是否尝试将光标移动到第一个条目? (
modelCursor.moveToFirst())
标签: android android-contentprovider google-nexus