0

EDIT: as I said, I read a lot but the question marked as duplicate is not the same scenario. I successfully load Intent Camera but I can't save/come back to my fragment and I'm not able to click button's camera to save it. Only come back works.


ok, I tried tons of code but I'm not able to find a solution. I tried my code in testbed and It works (with an MainActivity and two simple button) Now I moved my code to take a photo in my app; it correctly starts camera Intent and I can take a photo, but nothing append when I click the apply button. Only back button works. After a lot of change code , my code is below...and I see only that if I come back with arrow on Phone, when Intent Camera is closed, onActiveResult on MainActivity il called, but obviously without data.

Thanks in advance if you can point me on the right way!

in MainActivity:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);
}

in MyFragment:

foto.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {


            Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "/DCIM/Myapp/testPhoto.jpg")) );

            imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory()+"/DCIM/Myapp/testPhoto.jpg"));


            startActivityForResult(cameraIntent,CAMERA_REQUEST);

        }

and the onActivityResult in the same fragment:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    System.out.println("Called");
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {

        Bitmap bitmap=null;
        try{

            bitmap = BitmapFactory.decodeStream(getActivity().getContentResolver().openInputStream(imageUri));

        } catch (FileNotFoundException e) {

            e.printStackTrace();

        }
Magobin
  • 93
  • 2
  • 13
  • Possible duplicate of [onActivityResult is not being called in Fragment](https://stackoverflow.com/questions/6147884/onactivityresult-is-not-being-called-in-fragment) – ADM Mar 12 '18 at 15:53

1 Answers1

0

After many hours spent to find a solution......the problem simply was that I didn't check if directory where to save photo existed...In fact I changed directory for test purpose forgetting to change it in production. If it doesn't exist no error is reported but You can't save the photo currently loaded with intent !

Magobin
  • 93
  • 2
  • 13