2012-08-02 102 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