Error using Camera on Android 7.1

0

I'm having problems in a routine to take pictures, simple routine that in Android 4.1 to 6.0 has no problem more at 7 when trying to take a photo for the app, tried everything a week ago trying, looking for this problem in forums , but I almost quit because I can not see where else I can look and see if anyone has ever had 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 we 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();
    }
}
    
asked by anonymous 29.12.2017 / 20:42

1 answer

0

The error occurred when using the camera plus it was not there, from Android 7 they started looking at the bundle, so where onSaveInstanceState had I commented everything.

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

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

My activity had several fragments and in two of them and the one in the photo I kept data there. After commenting on the Crash problem, TransactionTooLargeException: data parcel size .... did not occur any more.

Thanks to Igor Morais for his strength.

    
30.12.2017 / 18:49