Get uri of picture taken by camera

erdomester

When the user takes a picture with the camera, I want the image displayed in an ImageView and I want to save the Uri to an online database. I heard saving the Uri of a picture is better than saving the path.

So this is how I start the camera:

intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getFile(getActivity()))); 
String a = String.valueOf(Uri.fromFile(getFile(getActivity())));
intent.putExtra("photo_uri", a);
startActivityForResult(intent, PICK_FROM_CAMERA);

where

private File getFile(Context context){
  File sdCard = Environment.getExternalStorageDirectory();
  File directory = new File (sdCard.getAbsolutePath() + "/Myapp");
  if (!directory.exists()) {
       directory.mkdirs();
  }
  String filename = "bl" + System.currentTimeMillis() + ".jpg";
  File newFile = new File(directory, filename);

  return newFile;
}

In onActivityResult:

Bundle extras = data.getExtras();
String photo_uri = extras.getString("photo_uri"); //null

This is always null. Btw before sending the intent the Uri looks like file://... instead of content:// which is the uri when I open an image from the gallery. I don't know if that's a problem.

Also, should I save the path instead of the Uri to the database? I read that the Uri can be complicated in certain phones or Android versions. When I let the user select an image from the gallery, I save the Uri to the database, so I think the best way is saving the Uri in this case as well.

I tried out many variations, but I get null every time I try to pass a variable with the intent...

erdomester

After starting the intent:

Intent intentPicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

startActivityForResult(intentPicture,PICK_FROM_CAMERA); 

In onActivityResult:

case PICK_FROM_CAMERA:

   Uri selectedImageUri = data.getData();
   InputStream imageStream = null;
   try {
       imageStream = getContentResolver().openInputStream(selectedImageUri);
   } catch (FileNotFoundException e) {
       e.printStackTrace();
   }
   Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);   
break;

That's all.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get uri from camera intent in android

From Dev

Android adding image to picture taken with camera

From Dev

Camera Orientation Change When Picture Taken. Even When Orientation is locked.

From Dev

Trying to display the picture in my app that was just taken with the built in camera app

From Dev

UIImagePickerController shows last picture taken instead of camera input

From Dev

Android - take picture - pass uri to camera app

From Dev

Get device orientation for photos taken with Android's default camera

From Dev

Images not being saved when picture is taken by camera app that isn't the stock camera

From Dev

Custom camera shows dark picture preview when photo taken on Nexus

From Dev

picture taken with camera doesn't resize in uiimageview

From Dev

Android - Get URI from Picture that i just have taken (without save the image again)

From Dev

Upload a picture taken by the camera to a server with limited size

From Dev

Android Camera: Get Picture Uri after the photo is taken

From Dev

How to set the size and quality of a picture taken with the android camera?

From Dev

Get IP camera's picture with HTTP request

From Dev

Android Camera Preview Stretched in Preview, Not After Picture Taken

From Dev

How to get the asset URL of a picture taken from UIImagePicker

From Dev

Getting the URL of picture taken by camera with Photos Framework

From Dev

Is there a way to specify the file name in advance for the picture taken with the flutter camera plugin?

From Dev

Android: Can't get the size of photo taken by camera acitivity

From Dev

Android - take picture - pass uri to camera app

From Dev

Strange size of picture taken with Android Camera

From Dev

Delete picture taken from camera

From Dev

How to show Picture into a activity after taken and saved from custom camera

From Dev

Decode datamatrix out of picture taken by camera2 with zxing

From Dev

Camera2 API picture taken wont show at gallery apps

From Dev

Get width and Height from URI of picture

From Dev

I cannot get a taken picture just pictures from screenshot

From Dev

Picture taken with camera as div background image Ionic 3

Related Related

  1. 1

    Get uri from camera intent in android

  2. 2

    Android adding image to picture taken with camera

  3. 3

    Camera Orientation Change When Picture Taken. Even When Orientation is locked.

  4. 4

    Trying to display the picture in my app that was just taken with the built in camera app

  5. 5

    UIImagePickerController shows last picture taken instead of camera input

  6. 6

    Android - take picture - pass uri to camera app

  7. 7

    Get device orientation for photos taken with Android's default camera

  8. 8

    Images not being saved when picture is taken by camera app that isn't the stock camera

  9. 9

    Custom camera shows dark picture preview when photo taken on Nexus

  10. 10

    picture taken with camera doesn't resize in uiimageview

  11. 11

    Android - Get URI from Picture that i just have taken (without save the image again)

  12. 12

    Upload a picture taken by the camera to a server with limited size

  13. 13

    Android Camera: Get Picture Uri after the photo is taken

  14. 14

    How to set the size and quality of a picture taken with the android camera?

  15. 15

    Get IP camera's picture with HTTP request

  16. 16

    Android Camera Preview Stretched in Preview, Not After Picture Taken

  17. 17

    How to get the asset URL of a picture taken from UIImagePicker

  18. 18

    Getting the URL of picture taken by camera with Photos Framework

  19. 19

    Is there a way to specify the file name in advance for the picture taken with the flutter camera plugin?

  20. 20

    Android: Can't get the size of photo taken by camera acitivity

  21. 21

    Android - take picture - pass uri to camera app

  22. 22

    Strange size of picture taken with Android Camera

  23. 23

    Delete picture taken from camera

  24. 24

    How to show Picture into a activity after taken and saved from custom camera

  25. 25

    Decode datamatrix out of picture taken by camera2 with zxing

  26. 26

    Camera2 API picture taken wont show at gallery apps

  27. 27

    Get width and Height from URI of picture

  28. 28

    I cannot get a taken picture just pictures from screenshot

  29. 29

    Picture taken with camera as div background image Ionic 3

HotTag

Archive