2

I'm trying to let the user pick an image from their library on Android. But when I use the PictureChooser plugin it does not seem to work (anymore)

I've seen this code working, but now it doesn't and I can't figure out why.

        var task = Mvx.Resolve<IMvxPictureChooserTask> ();
                task.ChoosePictureFromLibrary (1024, 92,
                    stream => {
                        MemoryStream ms = new MemoryStream ();
                        stream.CopyTo (ms);

                        _currentTarget.ImageBase64 = Convert.ToBase64String (ms.ToArray ());
                        SaveTarget ();
                        RaisePropertyChanged (() => TargetImage);
                    }, () => {

                    });

My log says the following:

mvx:Warning:1665,79 Warning - activity request code may clash with Mvx code for PickFromFile
mvx:Warning:1665,79 Warning - activity request code may clash with Mvx code for PickFromFile
mvx:Diagnostic:1665,82 OnMvxIntentResultReceived in MvxAndroidTask
mvx:Diagnostic:1665,82 OnMvxIntentResultReceived in MvxAndroidTask
mvx:Diagnostic:1665,83 ProcessMvxIntentResult started...
mvx:Diagnostic:1665,83 ProcessMvxIntentResult started...
mvx:Diagnostic:1665,84 Non-OK result received from MvxIntentResult - Canceled - request was 30001
mvx:Diagnostic:1665,84 Non-OK result received from MvxIntentResult - Canceled - request was 30001

The strange thing is, is that I do get a PictureChooser dialog but at the same time the assumeCancelled action gets called. And when I select an image, nothing happens anymore :(

i'm using mvvmcross 3.5.1

Jelle
  • 365
  • 3
  • 11

2 Answers2

1

It happened on some devices. Not All.

The reason was that I was starting the picturechooser plugin from a fragment (viewmodel). Therefore the result handling went wrong.

I could not find a fix right away, so instead I first navigate to an Activity and then start the picturechooser, which works fine for now.

Jelle
  • 365
  • 3
  • 11
0

As pointed out in https://stackoverflow.com/a/10564488/368379, when calling StartActivityForResult from a Fragment, the Request Code is changed by the Activity.

This should be fixed as of Android Support 23.2.0, which we are using with our Android Support packages for MvvmCross.

This has been an issue for many developers for over 3.5 years (thanks google!)

Community
  • 1
  • 1
Cheesebaron
  • 24,131
  • 15
  • 66
  • 118