2012-04-12 29 views
1

Helo guys,Uri字符串未在android中缓存

我正在使用以下代码。

   String fileName = "image" + "_" + title.getText().toString()+"_" + val.toString(); 
       photo = this.createFile(fileName, ".jpg"); 
       intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo)); 
       uriOfPhoto = Uri.fromFile(photo); 
       startActivityForResult(intent, RESULT_CAMERA_SELECT); 
      } 
     } 
     catch(Exception e) 
     { 
      Log.v("Error", "Can't create file to take picture!"); 
      displayAlert("Can't create file to take picture!","SDCard Error!"); 
     } 
    } 

    private File createFile(String part, String ext) throws Exception 
    { 
     File tempDir = new File (Environment.getExternalStorageDirectory() + "/MyFolder/Images"); 
     if(!tempDir.exists()) 
     { 
      tempDir.mkdir(); 
     } 
     tempDir.canWrite(); 
     return new File(tempDir, part+ext); 
    } 
}); 

UriOfPhoto是给我uriString在调试不chached。它不存储文件的URI。我可以如何解决这个问题。

authority Uri$Part$EmptyPart (id=830004244032) 
fragment Uri$Part$EmptyPart (id=830004245408) 
host "NOT CACHED" (id=830003914304) 
path Uri$PathPart (id=830067926736) 
port -2 
query Uri$Part$EmptyPart (id=830004245408) 
scheme "file" (id=830002660688)  
ssp null  
uriString "NOT CACHED" (id=830003914304) 
userInfo null  

问候

+0

您是否需要将捕获的图像存储在您的路径中:它或其他任何东西 – 2012-04-13 02:30:09

回答

0

这是不是足够的信息。你对你发送的意图采取了什么行动?你确定createFile实际上创建了一个文件吗?

您给出的错误列表不是很有用。它是来自调试的变量值列表的一部分吗?如果是这样,那么当您查看这些值时,您在代码中的位置?

+0

是的,它确实创建了一个新的file.uriOfPhoto = Uri.fromFile(photo);是我想要获得该文件照片的uri值的位置,但我得到了上面的 – 2012-04-13 02:14:19

0
String fileName = Environment.getExternalStorageDirectory() + "/MyFolder/Images" + fileName + ".jpg"; 
UriOfPhoto = Uri.parse(fileName); 
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.putExtra(MediaStore.EXTRA_OUTPUT, UriOfPhoto); 
startActivityForResult(intent, RESULT_CAMERA_SELECT); 

也没有必要创造店的照片,你只是需要通过URI在照片必须是Android操作系统上面创建你试图做一个文件文件,并存储所拍摄的图像中那个uri。