1

I have a folowing code:

public void take_picture(View view)
{


 Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
 startActivityForResult(cameraIntent, CAMERA_REQUEST); 
}


protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    ImageView slikaa = (ImageView)this.findViewById(R.id.slikaa);
    if ((requestCode == CAMERA_REQUEST)&& (resultCode == Activity.RESULT_OK)) {  

Bitmap photo = (Bitmap) data.getExtras().get("data"); 
        slikaa.setImageBitmap(photo);


} 

Now my question is how to get that image path(for saving it to my database), and then again, use it to show in a picture(I don't know how to get String paths, and then re-use it)

Gregor
  • 275
  • 1
  • 7
  • 19

2 Answers2

2

For getting Image Path in onActivityResult you will need to Start camera by send Image Path with Intent as:

       Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  

        //ContentValues values = new ContentValues();  
        ContentValues values = new ContentValues(3);  
        values.put(MediaStore.Images.Media.DISPLAY_NAME, "testing");  
        values.put(MediaStore.Images.Media.DESCRIPTION, "this is description");  
        values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");  
        imageFilePath = MainActivity.this.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);  
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageFilePath); 

        startActivityForResult(intent, CAMERA_REQUEST); 

and on onActivityResult

            protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
           ImageView slikaa = (ImageView)this.findViewById(R.id.slikaa);
            if ((requestCode == CAMERA_REQUEST)&& (resultCode == Activity.RESULT_OK)) {  
           //get image from path

            Bitmap photo = (Bitmap) data.getExtras().get("data"); 
            photo = BitmapFactory.decodeStream(this.getContentResolver()  
                .openInputStream(imageFilePath), null, op);  
            slikaa.setImageBitmap(pic);  

            //slikaa.setImageBitmap(photo);
          } 
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • 1
    What does "op" mean i this line: eStream(this.getContentResolver() .openInputStream(imageFilePath), null, op); I searched the net i found this options variable. But it doesn't wotk for me.... – Gregor Aug 27 '12 at 10:10
  • @Gregor: what does "op" represents? i also meet the same question now, do you solve that? – pearmak Feb 09 '13 at 14:06
  • I did'nt dig into it...I used only 'select from gallery intent' - the pictures that are already in the phone's gallery. I can help you with that, not with camera intent – Gregor Feb 12 '13 at 14:52
  • alright, apparently "op" is an option that can be derived from BitMapFactory.Option class. Take a look here: http://developer.android.com/training/camera/photobasics.html#TaskPath under "Decode a Scaled Image". I wish examples were provided complete – Nactus Mar 13 '15 at 01:04
0
String path;

Public void take_picture(){

    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
    File output = new File(dir,"gtumca.png");
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(output));
    path = output.getAbsolutePath(); <-------------
    startActivityForResult(cameraIntent, TAKE_PHOTO);

}
MAC
  • 15,799
  • 8
  • 54
  • 95