It appears as if OnActivityResult does not get called after accepting the picture taken from the camera.
Am I calling StartActivityForResult() wrong?, or is
Hmm.. I created a sample and it worked just fine for me. The only difference I see is that it looks like your override is not correct. It should be public override void OnActivityResult()
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var rootView = inflater.Inflate(Resource.Layout.MainFragment, container, false);
var button = rootView.FindViewById<Button>(Resource.Id.button_camera);
button.Click += (sender, args) =>
{
var intent = new Intent(MediaStore.ActionImageCapture);
StartActivityForResult(intent, 0);
};
return rootView;
}
public override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
Log.Debug("TestFragment", "Got result");
// do what you want with the result here
}
For the people that use Android.Support.V4.App Fragment. You can override the OnActivityResult method in your Fragment but it will never be called if you use this in combination with a FragmentActivity! It will be the OnActivityResult of the FragmentActivity that will be called. This can be implemented like following:
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
}
Try changing the data type of resultCode
to int
, instead of Result
and making the overridden function public
.
e.g.
public override void OnActivityResult(int requestCode, int resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
}
Check for request code is same as provided for startActivityForResult(intent, 0) here 0 is request code.. eg if you put 999 here insted of 0 ..then in onActivity result method check for requestcode == 999. it is used to check if the intent is the same as asked for and nothing other than that..
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0 && resultCode == RESULT_OK) { // ADD THIS
// Get Data and do something with it
}
}