我正在開發一個應用程序和ContentProvider以提供一些內部文件(二進制文件)。當我將它部署在三星Galaxy S,SII或任何其他設備上時,它可以很好地工作,當我在Galaxy Nexus或Nexus S上嘗試購買時,它無法正常工作!內容提供商不能在Nexus家庭設備上工作
場景:
我可以使用兩個URI訪問我的ContentProvider。根據這個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;
}
如果你需要一些代碼或什麼,只是要求它請!
非常感謝。
對於初學者:** ** 1有什麼確切的SDK版本出現在你的Android設備? ** 2。**每個設備上的確切* SQLite *版本是什麼('adb shell sqlite3 --version')** 3。**代碼是否在模擬器中正常工作? ** 4。**什麼是完整調用堆棧,當你得到* OutOfBoundsException *時? ** 5。* ModelCursor *如何實現? ** 6。**你的數據庫模型是什麼? ** 7。**你如何使用你的內容提供者(代碼)? – vArDo 2012-08-09 10:55:53
1.從2.3.3到4.0(各種設備)2.重要嗎?我可以檢查它們,但ModelCursor不從SQLite獲取數據,只是從內部文件存儲中獲取數據。 [要測試,謝謝]。 4. [鏈接](http://pastebin.com/NS7zBSGx)。來自「簡明英漢詞典」只需通過「getBlob」和其他需要的[link](http://pastebin.com/q4kMAEw3)。 6.不需要數據庫。 7.'Cursor modelCursor = getContentResolver()。query(Uri.parse(「content://」+ PROVIDER_NAME +「/ model」),null,null,new String [] {modelId},null);' - 'modelCursor .getBlob(0);' – manelizzard 2012-08-10 07:54:36
您是否嘗試將光標移至第一個條目? ('modelCursor.moveToFirst()') – SteveR 2012-08-10 16:21:57