S
S
Sasha Pleshakov2016-07-19 14:08:42
Android
Sasha Pleshakov, 2016-07-19 14:08:42

Why isn't the OnActivityResult method running?

protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);

            imageView = FindViewById<ImageView>(Resource.Id.imageView);

            Intent intent = new Intent(MediaStore.ActionImageCapture);
            App._file = new File("img", String.Format("myPhoto_{0}.jpg", DateTime.Now));
            intent.PutExtra(MediaStore.ExtraOutput, Uri.FromFile(App._file));
            StartActivityForResult(intent, 0);
        }

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
            Uri contentUri = Uri.FromFile(App._file);
            mediaScanIntent.SetData(contentUri);
            SendBroadcast(mediaScanIntent);

            App.bitmap = BitmapFactory.DecodeFile(App._file.Path);  
            if (App.bitmap != null)
            {
                imageView.SetImageBitmap(App.bitmap);
                App.bitmap = null;
            }
            GC.Collect();
        }

Everything works in the example . I can't figure out what I did wrong.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question