0

my app take a photo using intent. if i take with portrait orientation, i get the image. but when i rotate my device and take with landscape orientation, i got error. even the error message pointing to (maybe) the wrong line.

open camera:

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(mainActivity.getPackageManager()) != null) {
    startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}

on activity result:

Bundle extras = data.getExtras();
imageBitmap = (Bitmap) extras.get("data");
ivImage.setImageBitmap(imageBitmap);

giving result as explained. then i try again with other code.
open camera:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);

on activity result:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
imageBitmap = BitmapFactory.decodeFile(fileUri.getPath(), options);
ivImage.setImageBitmap(imageBitmap);

still have same result.
after looking some solution, they said about save instance. then i put this (i use fragment)

@Override
public void onSaveInstanceState(Bundle outState) {
    outState.putParcelable("file_uri", fileUri);
    super.onSaveInstanceState(outState);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    if (savedInstanceState != null)
        fileUri = savedInstanceState.getParcelable("file_uri");
    super.onActivityCreated(savedInstanceState);
}

still not working and one of the error message pointing to

super.onCreate(savedInstanceState);

in onCreate(Bundle savedInstanceState) function

anyone know why? or maybe another alternate code using camera.

update, error message:

Could not find class 'android.transition.Transition', referenced from method mypackagename.fragment.HomeFragment.access$super

and warning message

unable to resolve virtual method 949: Landroid/graphics/Bitmap;.getAllocationByteCount

gondai yosuke
  • 599
  • 2
  • 5
  • 19

1 Answers1

0

Add following code in your manifest

<activity
    android:name=".ActivityName"
    android:configChanges="orientation|screenSize|keyboardHidden"/>
Jenis Kasundra
  • 583
  • 9
  • 19