首页 文章

简单的代码,但游标仍然从内容提供程序返回null

提问于
浏览
0

这里有一个使用managedQuery游标的简单代码段的问题 . 两部分,代码的上半部分将字符串放入MediaStore数据库内容提供程序的LATITUDE列 .

下面代码的第二部分从数据库中读取相同的字符串 . 这是它返回null结果的地方 . 要么是因为字符串没有在代码的第一部分中正确读入数据库,要么在第二部分中有一个错误,它从数据库中读取它 .

我正在使用Media.images内容提供程序的LATITUDE列来存储字符串 . 没有其他未使用的列可用,这就是我使用它的原因 . 目标是将mp3文件的字符串路径名放入图像的LATITUDE列中,稍后再用另一个查询将其读回 .

我将问题跟踪到以下代码 . 代码的第二部分中的游标返回null . 我使用游标有什么问题,或者我不知道的一些错误?

String displayName; // string pathname of the mp3 file to be put into LATITUDE column
  String filename; // the pathname of the image that I want to add the database info to

  ContentValues imageValues = new ContentValues();
  String selection3 = MediaStore.Images.Media.DATA + "='" + filename +"'";
  imageValues.put(MediaStore.Images.Media.LATITUDE, displayName);
  getContentResolver().update(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
  imageValues, selection3, null);

  String[] proj6 = { MediaStore.Images.Media.LATITUDE };
  String selection6 = MediaStore.Images.Media.DATA + "='" + filename +"'";
  Cursor cursor2 = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
  proj6, selection6, null, null);
   cursor2.moveToFirst();        
  String displayer = (String)
  cursor2.getString(cursor2.getColumnIndex(MediaStore.Images.Media.LATITUDE));

1 回答

  • 0

    发现没有像我想象的那样的错误 . 这只是一个输入错误 .

    put方法有“Images.Media.LATITUDE”更新方法有“Audio.Media.LATITUDE”,将此更改为“Images.Media.LATITUDE”,就像它在put方法中一样,现在可以正常工作 .

    imageValues.put(MediaStore.Images.Media.LATITUDE, displayName);
      getContentResolver().update(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
      imageValues, selection3, null);
    

相关问题