Error while using Camera on Android 7.1

Asked

Viewed 108 times

0

I’m having problems in a routine to take pictures, simple routine that in Android 4.1 a 6.0 no longer have problem in 7 while trying to take a photo for the app, tried everything a week ago trying, looking for this problem in forums, more I’m almost giving up because I don’t see more where I can look and so see if anyone has been through this problem.

The Error is this

java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 1387072 bytes at 
android.app.ActivityThread$StopInfo.run(ActivityThread.java:3781)                                                                           
at android.os.Handler.handleCallback(Handler.java:751)

the code for the photo is the same as the one found in tutorials

    private void takePicture() {
    Log.i(TAG, "takePicture()");
    FirebaseCrash.log(TAG + " takePicture()");

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {

        arquivoFoto = getOutputMediaFile();

        if (arquivoFoto != null) {
            //Uri fotoURI = Uri.fromFile(arquivoFoto);
            Uri fotoURI = FileProvider.getUriForFile(getActivity(),
                    getActivity().getApplicationContext().getPackageName() + ".provider",
                    arquivoFoto);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fotoURI);
            startActivityForResult(takePictureIntent, PICK_FROM_CAMERA);
        }
    }
    FirebaseCrash.log(TAG + " takePicture() - pickImage()");
    FirebaseCrash.log(TAG + " takePicture() - Fim");
}

private File getOutputMediaFile(){
    Log.i(TAG, "getOutputMediaFile()");

    String appName = Helper.getAppName(getActivity());

    File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES), appName);
    Log.i(TAG, "getOutputMediaFile() - pasta " + mediaStorageDir.toString());

    if (!mediaStorageDir.exists()){
        if (!mediaStorageDir.mkdirs()){
            return null;
        }
    }

    String timeStamp = UUID.randomUUID().toString();
    File imagem = new File(mediaStorageDir.getPath() + File.separator +
            timeStamp + ".jpg");
    mCurrentPhotoPath = imagem.getAbsolutePath();
    Log.i(TAG, "getOutputMediaFile() -  mCurrentPhotoPath: " + mCurrentPhotoPath);
    return imagem;
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.i(TAG, "onActivityResult()");

    FirebaseCrash.log(TAG + " onActivityResult()");

    if (requestCode == PICK_FROM_CAMERA && resultCode == RESULT_OK) {
        salvarFoto();
    }
}

1 answer

0

The error occurred when using the camera but it was not there, from Android 7 they began to look at the Bundle, so where had onSaveInstanceState I commented all.

/*public void onSaveInstanceState(Bundle outState) {
   FirebaseCrash.log(TAG + ” onSaveInstanceState()“);

   outState.putSerializable(“listFotos”, (Serializable) fotos);
   super.onSaveInstanceState(outState);
}*/

my Activity had several Ragments and in two of them and the photo I kept data there. After commenting on the code the problems of Crash, Transactiontoolargeexception: data Parcel size.... no longer occurred.

Thanks to Igor Morais for the strength.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.