Reputation: 579
I'm calling ACTION IMAGE CAPTURE intent from a fragment, and I've implemented the onActivityResult()
in same fragment but the onActivityResult is not triggered while running it with my note2 device. Check the code snippets below that I used.
It worked fine when I am not using
import android.support.v4
Activity which I open fragment
public class HomeActivity extends FragmentActivity {
Fragment which I call Camera Intent
public class SaveCardFragment extends Fragment {
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 1888;
...
Calling Camera Intent
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
...
Function to detect activity result
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("Result", ""+requestCode);
}
Configuration in AndroidManifest
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<application
android:allowBackup="true" android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:theme="@style/AppTheme"
>
<activity android:name=".HomeActivity" android:label="@string/title_activity_home"/>
Upvotes: 1
Views: 1098
Reputation: 45503
I'm calling ACTION IMAGE CAPTURE intent from a fragment (...)
That's not quite true. Look at the following line of code:
getActivity().startActivityForResult(SaveCardFragment.this,intent,CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
Key to notice is that you call startActivityForResult()
on the hosting activity (HomeActivity
), not the fragment (SaveCardFragment
), hence the result is delivered to the activity and not propagated any further. If you want the result to be delivered to the fragment, ensure you call startActivityForResult()
on the fragment. In other words, just get rid of the getActivity()
prefix:
startActivityForResult(SaveCardFragment.this,intent,CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
See: Fragment#startActivityForResult
Upvotes: 1