我正在开发一个带有ContentProvider的应用程序,用于提供一些内部文件(二进制文件)。当我在三星Galaxy S、SII或其他任何设备上部署它时,它都能正常工作,但是当我在Galaxy Nexus或Nexus S上尝试时,它就无法工作了!
情景:
我的ContentProvider可以使用两个URI访问。根据此URI,提供程序会创建DataCursor(扩展CrossProcessCursor)或ModelCursor(也扩展CrossProcessCursos)。事实是,在Nexus系列中,我访问第一个游标(DataCursor)以检索标识符,并且它能够完美地工作,但是当访问第二个游标时,尝试使用"getBlob()"方法时总是抛出"OutOfBoundsException"异常。 提供程序
情景:
我的ContentProvider可以使用两个URI访问。根据此URI,提供程序会创建DataCursor(扩展CrossProcessCursor)或ModelCursor(也扩展CrossProcessCursos)。事实是,在Nexus系列中,我访问第一个游标(DataCursor)以检索标识符,并且它能够完美地工作,但是当访问第二个游标时,尝试使用"getBlob()"方法时总是抛出"OutOfBoundsException"异常。 提供程序
@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;
}
如果你需要任何代码或其他东西,请直接提出请求!
非常感谢。
adb shell sqlite3 --version
)? 3. 代码在模拟器中是否正常工作? 4. 当您收到OutOfBoundsException时,完整的调用堆栈是什么? 5. ModelCursor是如何实现的? 6. 您的数据库模型是什么? 7. 您如何使用您的内容提供程序(代码)? - vArDogetBlob
方法和其他所需方法[链接](http://pastebin.com/q4kMAEw3)。Cursor modelCursor = getContentResolver().query(Uri.parse("content://" + PROVIDER_NAME + "/model"), null, null, new String[] {modelId}, null);
-modelCursor.getBlob(0);
modelCursor.moveToFirst()
) - SteveR