我正在使用以下代码,我不想将图像存储在SDCard中。我GET异常,没有找到文件或目录。请给我一个提示,我错了!@!
case 0:
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
try {
photo = this.createTemporaryFile("Temp", ".jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
} catch(Exception e) {
Log.v("Error", "Can't create file to take picture!");
break;
}
startActivityForResult(intent, RESULT_CAMERA_SELECT);
break;
case 1:
intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult( intent, RESULT_MEMORY_SELECT );
break;
default:
break;
}
}
private File createTemporaryFile(String part, String ext) throws Exception
{
File tempDir= Environment.getRootDirectory();
tempDir=new File(tempDir.getAbsolutePath()+"/.temp/");
if(!tempDir.exists())
{
tempDir.mkdir();
}
return File.createTempFile(part, ext, tempDir);
}
最好的问候
答案 0 :(得分:0)
请确保您已将写入权限授予外部存储空间。
以这种方式创建文件怎么样:
String filePath= Environment.getExternalStorageDirectory()+"/myPic.jpeg";
File file=new File(filePath);
Uri output=Uri.fromFile(file);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, output);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
这段代码对我有用..