2011-07-26 27 views
3

我在我的设备(Nexus s)中安装了this应用程序。 它缓存一些图像,如果你使用这个应用程序。这就是为什么它会在我设备的画廊中显示缓存的图像。无法在Android中打开图像文件 - 文件未找到异常

我使用光标获取路径

final String[] columns = { MediaStore.Images.Media.DATA }; 
Cursor imagecursor = managedQuery(
     MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, 
     MediaStore.Images.Media._ID + " = " + id, null, MediaStore.Images.Media._ID); 
if (imagecursor != null && imagecursor.getCount() > 0){ 
    imagecursor.moveToPosition(0); 
    String path = imagecursor.getString(imagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)); 
    Log.d("path", path); 
    File f = new File("file://" + path); 
    Log.d("check_file", "" + f.exists()); 
} 

我得到的路径:

/mnt/sdcard/cache/hk.ignition.podcast/cartoon/2/http%3A% 2F%2Fbigcity.learnenglishapps.com%2Fimages%2Fcartoons%2Fset2%2Ffast食品 - 新1.png

下载图像: http://bigcity.learnenglishapps.com/images/cartoons/set2/fast-food-new-1.png

当我拉文件或探索像Astro这样的文件管理器时,它就在那里。 但是当我检查文件是否存在时,它说false

有没有人品问题?

更新:

删除file://工作检查文件中。

接下来是,我想在库中打开该文件。

  1. 我应该用这条路径来打开图片吗? 但是没有奏效:
 
    Intent intent = new Intent(); 
    intent.setAction(Intent.ACTION_VIEW); 
    intent.setDataAndType(
       Uri.parse("file:///mnt/sdcard/cache/hk.ignition.podcast/cartoon/2/http%3A%2F%2Fbigcity.learnenglishapps.com%2Fimages%2Fcartoons%2Fset2%2Ffast-food-new-1.png"), 
       "image/*"); 
    startActivityForResult(intent, 3); 
  1. 或者我应该尝试从MediaStore获得content://风格的路径?

更新2:

使用解决:

Uri.fromFile(f); 

而不是Uri.Parse()。由于它从编码格式构建/字符。

+0

我不知道很多关于什么是üDOIN ..但ü想想CURSOR持有FILE ..?或者它只是保留数据..? – ngesh

+0

在声明'Log.d(“路径”,路径);'我得到上面显示的正确路径 – Vikas

+0

你是对的..但我想你正在试图找到一个文件内的光标,其中保存对其中的图像内存的引用自己的方式,而不是确切的路径..你得到的东西不是确切的路径.. – ngesh

回答

2

变化new File("file://" + path)只是new File(path)

+0

嘿但是这对我来说还不够,对不起,你会看到我的更新有问题吗? – Vikas

+0

试试这个: 'intent.setDataAndType(intent.setDataAndType(Uri.fromFile(file),“image/*”);'这里的文件是你的'新建文件(“file://”+ path)' –

+0

同样的事情,我做了:-) – Vikas