简体   繁体   中英

How can I get the path to the picture from a Camera Intent

I just want to take a Foto with my cam -(that functions)

To use it further i need the path were the intent has saved the picture. But I don't want to tell the Intent where it should put the File. (Because now it just creates the file automatically.

Heres the function that starts the camera

public void doCam() {
    Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
    // startActivityForResult(intent,0);

    try {
        startActivityForResult(i, TAKEPICTURE_ACTIVITY);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this, "Application not available",
                Toast.LENGTH_SHORT).show();
    }
    // Log.e(TAG, "Error in taking picture");
}

and heres the getting of the results and I want in the string address the path with the name of the picture

I found different solutions already but the all involved choosing the filename before taking the picture -> so the app decided how the picutre will be named.

 public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    if (requestCode == TAKEPICTURE_ACTIVITY) {

        // super.onActivityResult(requestCode, resultCode, intent);
        if (resultCode == RESULT_OK) {

            Bundle extras = intent.getExtras();
            Bitmap bitmap = (Bitmap) extras.get("data");
            //doesn't work
            String address= (String) extras.get("EXTRA_OUTPUT");

该路径应该在intent.getData()找到。尝试一下。如果那里没有,那么您应该考虑强制相机将视频保存在自定义位置。

This is how you can get the path of the recently captured image:

    try{
    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
    startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
    } catch(Exception e){
        e.printStackTrace();
    }

And in the onActivityResult() method:

     String path=null;
            try{
                Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); 
                path=getLastImagePath();
            } catch(Exception e){
            }

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM