Getting a full-size image from the camera does not work on Galaxy S

I am having a problem capturing images from the built-in camera application on the Samsung Galaxy S.

I have a button in my application that, when clicked, launches the camera:

ContentValues values = new ContentValues();
values.put(Images.Media.MIME_TYPE, "image/jpeg");

mPicUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);

intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mPicUri.getPath());
startActivityForResult(intent, REQ_CODE_TAKE_PIC);

From what I read on interwebz, I can get a full-size photo using the URI that I passed to the intent. And so I have this on my onActivityResult:

Uri selectedImage = mPicUri;
String[] filePathColumn = {MediaStore.Images.Media.DATA};

Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();

int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();

And then, using the filePath variable, I set the image to ImageView. I get no image, and when I went through the code, I found that it was BitmapFactory.decodeFile()returning null.

Bitmap chosenPic = BitmapFactory.decodeFile(filePath);

, . , mPicUri URI, : content://media/external/images/media/90. , , , Path: /sdcard/DCIM/Camera/1285601413961.jpg. , , , , , . URI , :

URI is:           content://media/external/images/media/91
File path is:     /sdcard/DCIM/Camera/2010-09-27 23.30.30.jpg

, , , mPicUri, URI, .

? , , .

, .

+3
1

, ?

public static File getTempFile() {
    //it will return /sdcard/image.jpg
    final File path = new File(Environment.getExternalStorageDirectory(), "MyApp");
    if (!path.exists()) {
        path.mkdir();
    }
    return new File(path, "image.jpg");
}

.

0

Source: https://habr.com/ru/post/1766802/


All Articles