2

I'm working on a new app. The app uses the camera and the external storage. While on my LG G3 the app works fine, (as well as on the AVD emulator), when testing it on a Samsung S5, when I get the result from the camera, after taking the photo (in the onActivityResult Method) it seems like there is no result. The Intent is null. I'll just add and say that the photo is being taken, and saved in the specified location, but for some reason i cant use it. As said, the same exact code works fine on my G3.

I've also tried to create a camera test-app from scratch, again it works only on the G3 and emulator.

code:

static final int REQUEST_TAKE_PHOTO = 1;

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(photoFile));
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
}

String mCurrentPhotoPath;    
Bitmap bitmapImg;


private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
            imageFileName,  /* prefix */
            ".jpg",         /* suffix */
            storageDir      /* directory */
    );

    // Save a file: path for use with ACTION_VIEW intents
    mCurrentPhotoPath = image.getAbsolutePath();
    return image;
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
        /*Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");
        mImageView.setImageBitmap(imageBitmap);*/

        bitmapImg = BitmapFactory.decodeFile(mCurrentPhotoPath);
        mImageView.setImageBitmap(bitmapImg);
    }
}


@Override
public void onClick(View view) {
    dispatchTakePictureIntent();
}

Also as said, the data Intent is null only on the samsung phone. Is there anything different on S5 regarding camera, Or permmisions? I'd love to get some help, It is very important to me. Thanks in advance.

Gil Maimon
  • 153
  • 8

1 Answers1

0

For me the whole problem was:

 android:launchMode="singleInstance"

In the AndroidManifest. Removing it solved it.

Uriel Frankel
  • 14,304
  • 8
  • 47
  • 69