Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Xam.Plugin.Media after camera capture app crashes without any error

edited June 2020 in Xamarin.Forms


I am using Xam.Plugin.Media in my xamarin forms (Xamarin.Forms mobile app. App gets crashed after camera capture strangely without any error. Camera captured image also gets stored in the desired folder I set. I don't know how to proceed further, would appreciate if someone could help me move forward.

Code snippet and other App details are attached below:

Shared Project


            < ResourceDictionary>
                < services:Null2StringConverter x:Key="Null2String"/>
                < services:ByteToImageFieldConverter x:Key="ByteArrayToImage"/>
            < /ResourceDictionary>

    <Grid ColumnSpacing="16">
        <StackLayout Grid.Column="0">
                Source="{Binding PhotoByte, Converter={StaticResource ByteArrayToImage}, Mode=TwoWay}" />
        <StackLayout  Grid.Column="1">
            <Button Grid.Column="1" WidthRequest="200"
                x:Name= "btnTake"
                Text = "Take Picture"
                Style="{StaticResource ButtonBlueWhite}"
                HorizontalOptions = "End"/>


    public partial class PODUpdate : ContentPage
            PODViewModel viewModel;

                public PODUpdate()

                        BindingContext = viewModel = new PODViewModel(2);

                private void BtnTake_Clicked(object sender, EventArgs e)

                private async void PictureClick()
                        if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                            await DisplayAlert("No Camera", ":( No camera available.", "OK");

                        string mFileName = DateTime.Now.Year.ToString() +
                                            DateTime.Now.Month.ToString() +
                                            DateTime.Now.Day.ToString() +
                                            DateTime.Now.Hour.ToString() +
                                            DateTime.Now.Minute.ToString() +

                        await CrossMedia.Current.Initialize();

                        var photo = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                            MaxWidthHeight = 2500,
                            CompressionQuality = 80,
                            DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Front,
                            Name = mFileName,
                            PhotoSize = Plugin.Media.Abstractions.PhotoSize.Small

                        if (photo == null)

                        if (photo != null)
                            viewModel.IsPhotoTaken = true;
                            viewModel.PhotoByte = System.IO.File.ReadAllBytes(photo.Path);

                    catch (Exception ex)
                        await DisplayAlert(this.Title, ex.Message+ ex.InnerException, "Ok");

Android Project

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="" android:versionCode="1" android:versionName="1.0" package="com.Flyking.ibots.netmobile" android:installLocation="auto">
        <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
        <application android:label="Ibots.NetMobile.Android" android:icon="@drawable/FlykingIcon">
            <provider android:name="" android:authorities="com.Flyking.ibots.netmobile.fileprovider" android:exported="false" 
                  android:largeHeap="true" android:grantUriPermissions="true">
                <meta-data android:name="" android:resource="@xml/file_paths"></meta-data>
      <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.CAMERA" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.FLASHLIGHT" />


    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using Android.App;

    // General Information about an assembly is controlled through the following 
    // set of attributes. Change these attribute values to modify the information
    // associated with an assembly.
    [assembly: AssemblyTitle("Ibots.NetMobile.Android")]
    [assembly: AssemblyDescription("")]
    [assembly: AssemblyConfiguration("")]
    [assembly: AssemblyCompany("")]
    [assembly: AssemblyProduct("Ibots.NetMobile.Android")]
    [assembly: AssemblyCopyright("Copyright ©  2014")]
    [assembly: AssemblyTrademark("")]
    [assembly: AssemblyCulture("")]
    [assembly: ComVisible(false)]

    // Version information for an assembly consists of the following four values:
    //      Major Version
    //      Minor Version 
    //      Build Number
    //      Revision
    // You can specify all the values or you can default the Build and Revision Numbers 
    // by using the '*' as shown below:
    // [assembly: AssemblyVersion("1.0.*")]
    [assembly: AssemblyVersion("")]
    [assembly: AssemblyFileVersion("")]

    // Add some common permissions, these can be removed if not needed
    [assembly: UsesPermission(Android.Manifest.Permission.Internet)]
    [assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
    #if DEBUG
        [assembly: Application(Debuggable = true, UsesCleartextTraffic = true)]
        [assembly: Application(Debuggable = false, UsesCleartextTraffic = true)]

    [assembly: UsesPermission(Android.Manifest.Permission.Camera)]
    [assembly: UsesFeature("", Required = true)]
    [assembly: UsesFeature("", Required = true)]


    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity

            protected override void OnCreate(Bundle savedInstanceState)
                TabLayoutResource = Resource.Layout.Tabbar;
                ToolbarResource = Resource.Layout.Toolbar;

                Rg.Plugins.Popup.Popup.Init(this, savedInstanceState);

                Xamarin.Essentials.Platform.Init(this, savedInstanceState);
                global::Xamarin.Forms.Forms.Init(this, savedInstanceState);


                LoadApplication(new App());

            public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
                global::ZXing.Net.Mobile.Forms.Android.PermissionsHandler.OnRequestPermissionsResult(requestCode, permissions, grantResults);

                Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

                base.OnRequestPermissionsResult(requestCode, permissions, grantResults);


Thanks - G Rajesh

Best Answer

    Accepted Answer

    Thanks again LeonLu. Appreciate it.

    Finally I figured out what the real problem was:

    In the android project, MainActivity.cs
    [Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true]

    Basically After removing Nohistory attribute, the app didn't crash post image capture.

    Thanks again

    G Rajesh


  • LeonLuLeonLu Member, Xamarin Team Xamurai

    I test this plugin with Xamarin.Forms, other nuget packages verson like following screenshot.

    Here is running gif.

    Here is my demo, you can download my demo, then run it in your device, if it could running normally.


    Thanks LeonLu.

    However, I tried your code to adapt in my project and the application still crashes. Even my earlier code if i try on a brand new project, it works.

    Is there any project level setting which is bothering ?

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    You can try to update your nuget package to latest version, then delete bin and obj folders, rebuild your project, if this issue will disappear.

    Accepted Answer

    Thanks again LeonLu. Appreciate it.

    Finally I figured out what the real problem was:

    In the android project, MainActivity.cs
    [Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true]

    Basically After removing Nohistory attribute, the app didn't crash post image capture.

    Thanks again

    G Rajesh

Sign In or Register to comment.