0

I have been searching for the following issue for three days

My Code is as following

private void openCamera () {    
    try {
        Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        String fileName = Constants.IMAGE_CAPTURE_FILE_NAME_PREFIX + System.currentTimeMillis() + Constants.IMAGE_FILE_EXT_JPG;
        mImageFile = new File(FileManager.getInstance().getFileFullName(Constants.IMAGE_FOLDER, fileName));
        captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageFile);
        startActivityForResult(captureIntent, Constants.ACTIVITY_CAMERA_REQUEST_CODE);     
    } catch(ActivityNotFoundException anfe) {   
        String errorMessage = "Whoops - your device doesn't support capturing images!";
        Toast toast = Toast.makeText(ImagesSelectorActivity.this, errorMessage, Toast.LENGTH_SHORT);
        toast.show();
    }
}



public String getFileFullName(String folderName, String fileName) {
    String filepath;
    if (PhoneUtils.isSDCardFound() == true)
        filepath = Environment.getExternalStorageDirectory().getPath();
    else
        filepath = Environment.getDataDirectory().getPath();

    File file = new File(filepath, folderName);

    if (!file.exists()) {
        file.mkdirs();
    }

    return (file.getAbsolutePath() + "/" + fileName);
}

On Activity results

if(requestCode == Constants.ACTIVITY_CAMERA_REQUEST_CODE) {

    Uri picUri = data.getData();

    if (picUri == null) {
        Bitmap bitmap = (Bitmap) data.getExtras().get("data");
        Uri tempUri = PhoneUtils.getBitmapUri(getApplicationContext(), bitmap);
        Log.i("AMIRA", tempUri.toString());

    }

    performPreview(picUri);
}

The problem that the image is not saved in my folder, and the url that return is the thumbnail uri

I need to save the image after capture in the path that I need and to be able to read the full size of image.

I can't find the image captured from camera in any place in the device.

ThomasThiebaud
  • 11,331
  • 6
  • 54
  • 77
Amira Elsayed Ismail
  • 9,216
  • 30
  • 92
  • 175

2 Answers2

1

I use almost same process as yours that works fine. Please try doing the following:

In the open camera part, instead of sending File send Uri like this:

mImageUri = Uri.fromFile(mImageFile); //keep mImageUri as member so that you can use it on the activity result.
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);  

Afterwards in onActivityResult just do this:

if (mImageUri != null && !mImageUri.getPath().isEmpty()) {
    performPreview(mImageUri);
}

Hope this helps!

Obaida.Opu
  • 444
  • 1
  • 4
  • 18
  • You are right, [`MediaStore.EXTRA_OUTPUT`](http://developer.android.com/intl/zh-tw/reference/android/provider/MediaStore.html#EXTRA_OUTPUT) accepts Uri, not File and not file path. Note also that `mImageFile` must be writable for the Camera app; make sure it sits in a folder that is not private to your app. – Alex Cohn Oct 13 '15 at 07:42
  • Thanks a lot for your help. – Amira Elsayed Ismail Oct 14 '15 at 14:10
0

Class file as follows :

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MyCameraActivity extends Activity {
private static final int CAMERA_REQUEST = 1888; 
private ImageView imageView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    this.imageView = (ImageView)this.findViewById(R.id.imageView1);
    Button photoButton = (Button) this.findViewById(R.id.button1);
    photoButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
            startActivityForResult(cameraIntent, CAMERA_REQUEST); 
        }
    });
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {  
        Bitmap photo = (Bitmap) data.getExtras().get("data"); 
        imageView.setImageBitmap(photo);
    }  
} 

}

XML file :

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 >

 <Button android:id="@+id/button1" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:text="Take Picture">
 </Button>

<ImageView 
android:id="@+id/imageView1"   
android:layout_height="wrap_content" 
android:src="@drawable/ic_launcher" 
android:layout_width="wrap_content">
</ImageView>

Add Permission in Manifest file :

<uses-feature android:name="android.hardware.camera"></uses-feature> 

Hope this helps...

Naveen
  • 814
  • 2
  • 9
  • 22
  • you may not notice that using Bitmap photo = (Bitmap) data.getExtras().get("data"); is retrieving thumbnail image size and I want to view full image size. – Amira Elsayed Ismail Oct 12 '15 at 10:27
  • refer this link http://stackoverflow.com/questions/6448856/android-camera-intent-how-to-get-full-sized-photo – Naveen Oct 12 '15 at 10:34