我使用的下面的代碼
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 not chached in debug。它不是存儲文件中的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
photo 的值是確定的,
photo = this.createFile(fileName, ".jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
uriOfPhoto = Uri.fromFile(photo);
為什麼還在這裡實例化uriOfPhoto, 有點多余。 在用到的時候在實例化