Media Plugin - Photo

ValdirRosendoValdirRosendo BRMember ✭✭

i´m using plugin Media Plugin created by James Montemagno, but after i take new photo my app go back to the login form.

it´s only happens when i take new photo by camera, in the same code if i set the photo manually, the app don´t changes the form and shows the correct image.


Automatic (Origim Camera): customImage.Source = ImageSource.FromFile(file.Path);

Complete Code:

clickMe.Clicked += async (sender, args) => {
StackLayout stack = ((Button)sender).Parent as StackLayout;
List LstCustomLabel = new List ();
foreach (View v in stack.Children) {
if (v.GetType () == Type.GetType ("SyncForm.CustomImage"))
LstCustomLabel.Add (v as CustomImage);
CustomImage customImage = LstCustomLabel.FirstOrDefault (x => x.NameCustom == "imgphoto" + ((Button)sender).StyleId.ToString());

if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
//DisplayAlert("No Camera", ":( No camera avaialble.", "OK");

var file = await CrossMedia.Current.TakePhotoAsync(new Media.Plugin.Abstractions.StoreCameraMediaOptions
Directory = "Sample",
Name = "test.jpg",
DefaultCamera= CameraDevice.Rear,

if (file == null)
//DisplayAlert("File Location", file.Path, "OK");

//customImage.Source = ImageSource.FromStream(() =>
// {
// var stream = file.GetStream();
// file.Dispose();
// return stream;
// });

//customImage.Source = ImageSource.FromFile("/storage/sdcard0/Android/data/SyncForm.SyncForm/files/Pictures/Sample/test_6.jpg");
customImage.Source = ImageSource.FromFile(file.Path);


My Phone using Android 4.0.3

Valdir Rosendo


  • hvaughanhvaughan USMember ✭✭✭

    This is the same thing that I ran into using that plugin as well as things like Device.OpenUri. You most likely, like me, have code in App.OnResume() which forces the user to log back in after they have left the application. Doing things like taking pictures or opening the device's browser will force these App events to fire.

    If so, I used a couple things to help with this. The first thing I did was to add the following into my App class:
    public static bool SkipPinCheck;

    Then before running code that I know will force the user to leave the app (such as taking a photo), I set SkipPinCheck to true.

    Then in OnResume() I check that variable and decide what to do from there.

    In my case, I might send the user out of the app to view a PDF or something and so I worried that they might just leave the app and not come back from a while so I added code into OnSleep() which sees if SkipPinCheck is true and if so, puts the current DateTime into a variable. Then in OnResume() I do the same SkipPinCheck code but I add another condition to see if 5 min or more have passed. If so, I force them to login even though SkipPinCheck is set to true.

    Also, don't forget to set SkipPinCheck back to false at the very end of OnResume().

    If you would like to see some code I can probably help with that as well. Hope this helps.

  • StefanoChiariStefanoChiari IEMember ✭✭

    @ValdirRosendo I have same problem. Did you find a solution ?

Sign In or Register to comment.