Get uri from camera intent in android

user782104

on click

 takePic.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent m_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                imageUri = getImageUri();
                m_intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                startActivityForResult(m_intent, REQUEST_IMAGE_CAPTURE);
            }
        });

On Result:

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_IMAGE_CAPTURE
                    && resultCode == RESULT_OK) {   

                Log.d("test1",""+imageUri);
                Intent shareIntent = new Intent(this, SharePicForm.class);
                shareIntent.putExtra("photo",""+imageUri);
                startActivity(shareIntent);
            }

        }

getImageUri()

private Uri getImageUri(){
        Uri m_imgUri = null;
        File m_file;
        try {
            SimpleDateFormat m_sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
            m_curentDateandTime = m_sdf.format(new Date());
            m_imagePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + m_curentDateandTime + ".jpg";
            m_file = new File(m_imagePath);
            m_imgUri = Uri.fromFile(m_file);
        } catch (Exception p_e) {
        }
        return m_imgUri;
    }

What I would like to achieve is very simple, call camera intent and get the uri of the result photo. But it seems there is an inconsistent of different device and on my device it isn't work at all. I tried to store the path on a public variable but when I retrieve it , it is null, is there formal and standard way to implement it and should be work on all device? Also, are there any way for not provide the custom path but get the default uri path from the camera intent ?

Thanks for helping

Alex Cohn

If your device does not respect cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, you still can use

Uri imageUri = data.getData();

in onActivityResult(int requestCode, int resultCode, Intent data). But in most cases, the problem is that RAM is limited, and the system destroys your activity to give enough memory to the camera app to fulfill your intent. Therefore, when the result is returned, the fields of your activity are not initialized, and you should follow Amit's suggestion and implement onSavedInstance() and onRestoreInstanceState().

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

camera intent from Android website not working - Android

From Dev

camera intent from Android website not working - Android

From Dev

how to get data from intent in the form of uri?

From Dev

how to get data from intent in the form of uri?

From Dev

Getting the URI from an Android NFC Intent

From Dev

fileNotFoundException camera intent - Android

From Dev

camera and gallery intent to get image and copy in another folder in android

From Dev

Returning from Web Intent, Android camera app stops

From Dev

Android : Take a photo from with in my layout without starting a camera intent

From Dev

Android Camera: Get Picture Uri after the photo is taken

From Dev

Android - start an activity from command line using intent uri

From Dev

Using android camera with an explicit intent

From Dev

Android camera and photo picker intent

From Dev

Using android camera with an explicit intent

From Dev

Can't get URI of captured screenshot from intent.getParcelableExtra(Intent.EXTRA_STREAM)!

From Dev

Android - Get same intent from different activities

From Dev

Get vCard from Contactdata Intent - Android

From Dev

Android PreferenceFragment Get Result From Intent

From Dev

Android - Get same intent from different activities

From Dev

Android PreferenceFragment Get Result From Intent

From Dev

Get uri of picture taken by camera

From Dev

Taking audio uri from intent

From Dev

Android get full size image from camera

From Dev

android : capturing image from Camera it get a null

From Dev

Android Camera Intent crashes with Android L

From Dev

Android Camera Intent crashes with Android L

From Dev

get Path name from Uri Android Lollipop

From Dev

android: Get real path from uri

From Dev

Get absolute path from Uri in Android 10

Related Related

  1. 1

    camera intent from Android website not working - Android

  2. 2

    camera intent from Android website not working - Android

  3. 3

    how to get data from intent in the form of uri?

  4. 4

    how to get data from intent in the form of uri?

  5. 5

    Getting the URI from an Android NFC Intent

  6. 6

    fileNotFoundException camera intent - Android

  7. 7

    camera and gallery intent to get image and copy in another folder in android

  8. 8

    Returning from Web Intent, Android camera app stops

  9. 9

    Android : Take a photo from with in my layout without starting a camera intent

  10. 10

    Android Camera: Get Picture Uri after the photo is taken

  11. 11

    Android - start an activity from command line using intent uri

  12. 12

    Using android camera with an explicit intent

  13. 13

    Android camera and photo picker intent

  14. 14

    Using android camera with an explicit intent

  15. 15

    Can't get URI of captured screenshot from intent.getParcelableExtra(Intent.EXTRA_STREAM)!

  16. 16

    Android - Get same intent from different activities

  17. 17

    Get vCard from Contactdata Intent - Android

  18. 18

    Android PreferenceFragment Get Result From Intent

  19. 19

    Android - Get same intent from different activities

  20. 20

    Android PreferenceFragment Get Result From Intent

  21. 21

    Get uri of picture taken by camera

  22. 22

    Taking audio uri from intent

  23. 23

    Android get full size image from camera

  24. 24

    android : capturing image from Camera it get a null

  25. 25

    Android Camera Intent crashes with Android L

  26. 26

    Android Camera Intent crashes with Android L

  27. 27

    get Path name from Uri Android Lollipop

  28. 28

    android: Get real path from uri

  29. 29

    Get absolute path from Uri in Android 10

HotTag

Archive