i've used code from link below,was very helpfull,thank you: http://www.tutorialforandroid.com/2010/10/take-picture-in-android-with.html
need help with some photo issues! takePhoto() starts MediaStore.ACTION_IMAGE_CAPTURE, getFile() creates "Image keeper" directory and then saves taken picture under "Image-SOMENUMBER.jpg" name!in onActivityResult() i'd like to show taken picture as ImageView and i'd like to rename picture to something user inputs in edittext or something!
have two questions:
1) why can't i get ImageView to show my picture in try{} part? what am i doing wrong? how can i get a path of saved image?
2) is there a way i can enable users to name photos the way they want?(something like "save as" or renaming on some button click ect.)
any idea is welcome!thank you!
here is the code:
private static final int TAKE_PHOTO_CODE = 1;
private void takePhoto(){
final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getFile(this)) );
startActivityForResult(intent, TAKE_PHOTO_CODE);
}
private File getFile(Context context){
final File path = new File( Environment.getExternalStorageDirectory(), "Image keeper" );
if(!path.exists()){
path.mkdir();
}
String name;
int n = 100000;
int rand;
rand = new Random().nextInt(n);
name = "Image-" + rand + ".jpg";
File file = new File(path,name);
return file;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch(requestCode){
case TAKE_PHOTO_CODE:
final File file = getFile(this);
try {
Bitmap captureBmp;
captureBmp = Media.getBitmap(getContentResolver(), Uri.fromFile(file) );
iv = (ImageView) findViewById(R.id.imageView1);
iv.setImageBitmap(captureBmp);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
break;
}
}
}