2012-08-02 103 views
11

我正在開發一個應用程序和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; 
    } 

如果你需要一些代碼或什麼,只是要求它請!

非常感謝。

+0

對於初學者:** ** 1有什麼確切的SDK版本出現在你的Android設備? ** 2。**每個設備上的確切* SQLite *版本是什麼('adb shell sqlite3 --version')** 3。**代碼是否在模擬器中正常工作? ** 4。**什麼是完整調用堆棧,當你得到* OutOfBoundsException *時? ** 5。* ModelCursor *如何實現? ** 6。**你的數據庫模型是什麼? ** 7。**你如何使用你的內容提供者(代碼)? – vArDo 2012-08-09 10:55:53

+0

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 [] {m​​odelId},null);' - 'modelCursor .getBlob(0);' – manelizzard 2012-08-10 07:54:36

+2

您是否嘗試將光標移至第一個條目? ('modelCursor.moveToFirst()') – SteveR 2012-08-10 16:21:57

回答

1

最後我得到了答案。由於設備,但這是由於Android操作系統版本。

從4.0.3開始的早期版本的AbstarctCursor方法實現的方法是單向的,對於第一個項目來說不需要將光標位置設置爲0。 4.0.3(as seen here)後,該方法進行了修改,從而導致上光標位置沒有設置爲0

的拋出異常是:

07-31 11:35:09.938: W/System.err(2760): android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1 
07-31 11:35:09.985: W/System.err(2760):  at android.database.AbstractCursor.checkPosition(AbstractCursor.java:418) 
07-31 11:35:09.989: W/System.err(2760):  at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136) 
07-31 11:35:09.989: W/System.err(2760):  at android.database.AbstractWindowedCursor.getBlob(AbstractWindowedCursor.java:44) 
07-31 11:35:09.993: W/System.err(2760):  at android.database.CursorWrapper.getBlob(CursorWrapper.java:122) 
07-31 11:35:09.993: W/System.err(2760):  at es.agnitio.kivox.mobile.internal.ModelImporterAndroidImpl.importModelPackage(ModelImporterAndroidImpl.java:44) 
07-31 11:35:09.993: W/System.err(2760):  at es.agnitio.kivox.mobile.internal.KivoxMobileBasicCode.importModel(KivoxMobileBasicCode.java:159) 
07-31 11:35:09.997: W/System.err(2760):  at es.agnitio.kivox.mobile.internal.KivoxMobileBasicImpl.importModel(KivoxMobileBasicImpl.java:47) 
07-31 11:35:09.997: W/System.err(2760):  at es.agnitio.kivoxmobile.testing.KivoxMobileBasicTrial.onCreate(KivoxMobileBasicTrial.java:63) 
07-31 11:35:09.997: W/System.err(2760):  at android.app.Activity.performCreate(Activity.java:5008) 
07-31 11:35:10.001: W/System.err(2760):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 
07-31 11:35:10.001: W/System.err(2760):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 
07-31 11:35:10.001: W/System.err(2760):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
07-31 11:35:10.004: W/System.err(2760):  at android.app.ActivityThread.access$600(ActivityThread.java:130) 
07-31 11:35:10.004: W/System.err(2760):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
07-31 11:35:10.004: W/System.err(2760):  at android.os.Handler.dispatchMessage(Handler.java:99) 
07-31 11:35:10.008: W/System.err(2760):  at android.os.Looper.loop(Looper.java:137) 
07-31 11:35:10.008: W/System.err(2760):  at android.app.ActivityThread.main(ActivityThread.java:4745) 
07-31 11:35:10.008: W/System.err(2760):  at java.lang.reflect.Method.invokeNative(Native Method) 
07-31 11:35:10.012: W/System.err(2760):  at java.lang.reflect.Method.invoke(Method.java:511) 
07-31 11:35:10.012: W/System.err(2760):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
07-31 11:35:10.012: W/System.err(2760):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
07-31 11:35:10.016: W/System.err(2760):  at dalvik.system.NativeStart.main(Native Method) 

其示出了(深入研究之後),光標索引不在fillWindow()上設置。

SOLUTION

爲了解決這種「碎片化」的問題,只是添加moveToPosition(0)的方法,如moveToFirst()move()(有一些應用程序邏輯)您的自定義光標。這將使遊標索引被設置爲0,避免了「-1」索引請求異常。

希望它可以幫助任何人=)

0

我需要的是一個水晶球爲這一個有點,但是...你可以嘗試兩件事情:

  • 將光標移動到第一個條目,如SteveR建議。

  • 其次,我在戴爾Streak 7「平板電腦上工作時遇到了類似的問題,它被認爲是訪問其內部存儲設備的特殊例外設備列表的一部分。與if語句來分類的。這可能是類似的東西,但我對此表示懷疑,尤其是Nexus的應該是開發商的設備。

也許你應該嘗試運行最簡單的可能的ContentProvider測試應用程序並看看它是如何在這些設備上的行爲。

+0

對不起,遲到的答案。我已經測試過所有這些。重點是'moveToFirst()'返回'false'。這就像系統無法找到提供商,很奇怪,因爲在其他設備中找到它。 – manelizzard 2012-08-28 07:23:09