i am using following code and i don't want to store images in SDCard. i GET Exception, no file or directory found. Please give me a hint where am i wrong !@!
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);
}
Best Regards
Make sure, you put permission of writing to external storage.
and What about creating file this way:
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);
This code is working for me..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.