0

ANSWER IS HERE

Thanks guys for all the help.


I've got a Fragment with code that allows user to take a photo. After photo gets taken other actions take place. My problem is that these other actions don't get initiated.

Here's the code. I never receive the "Photo Taken" message in LogCat.

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == TAKE_PHOTO_CODE) {
        if(resultCode ==  Activity.RESULT_OK) {

            Log.i("Debug", "Photo Taken");

        }

    }
}

I tried changing Activity.RESULT_OK to MainActivity.this, MainActivity and getActivity(), but no use.

Take photo code:

 centCamera.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
             count++;
            file = dir+count+".jpg";
            currentPhotoString = file;
            File newfile = new File(file);
            try {
                newfile.createNewFile();
            } catch (IOException e) {}       

            Uri outputFileUri = Uri.fromFile(newfile);

            Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
            startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);


            someMethod();

           Handler handler = new Handler();
          handler.postDelayed(new Runnable(){
          @Override
                public void run(){
           sideCamera.setEnabled(true);
             sideCamera.setVisibility(View.VISIBLE);



       centCamera.setEnabled(false);
       centCamera.setVisibility(View.GONE);
         }
         }, 500);


        }
    });
Community
  • 1
  • 1
Oleksandr Firsov
  • 1,428
  • 1
  • 21
  • 48

2 Answers2

0

I never receive the "Photo Taken" message in LogCat.

Have you made any changes to your Activity's onActivityResult method?This might be because it would ultimately call onActivityResult of your Activity first. and as you did not pass the same callback to your Fragment 's onActivityResult you are not getting your callback in your Fragment

So, do something like below in your activity's onActivityResult

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(frag_yourfrag!=null){
    frag_yourfrag.onActivityResult(requestCode,resultCode,data);
     }
}

where frag_yourfrag is referring to your instance of Fragment class you call from Activity

Bhavesh Patadiya
  • 25,740
  • 15
  • 81
  • 107
0

Try by overriding onActivityResult in your activity:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
}

After that, the result should be passed to your fragment which holds the instance of ViewPager.

If you want the result in one of ViewPager's fragment then in Fragment which holds the ViewPager do this:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    List<Fragment> fragments = getChildFragmentManager().getFragments();
    if (fragments != null) {
        for (Fragment fragment : fragments) {
            if (fragment != null) {
                fragment.onActivityResult(requestCode, resultCode, data);
            }
        }
    }

    super.onActivityResult(requestCode, resultCode, data);
}
flyingAssistant
  • 872
  • 7
  • 19