hello I am working on a app that allows users to take pictures of notes and then send them to a friend. I am using xamarin forms do build this app and I am also using the media plugin to access the native camera but the user has to press a button to open the native camera so My question is how do I get the camera to load as soon as the user open's the app?
heres my xaml code:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SnapNote.CameraPage"
xmlns:local="clr-namespace:AppName;"
BackgroundColor="{x:Static local:Colors.BackgroundColor}">
<ContentPage.Padding>
<OnPlatform
x:TypeArguments="Thickness"
iOS="10,20,10,10"
Android="10,10,10,10" />
</ContentPage.Padding>
<StackLayout>
<Image Source="TakePhotoButton.png">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="Handle_Clicked" />
</Image.GestureRecognizers>
</Image>
<Image x:Name="image"/>
<Image Source="SendNoteButton.png">
</Image>
</StackLayout>
</ContentPage>
and heres the code behind:
using System;
using System.Collections.Generic;
using Plugin.Media;
using Plugin.Media.Abstractions;
using Xamarin.Forms;
namespace AppName
{
public partial class CameraPage : ContentPage
{
public CameraPage()
{
InitializeComponent();
}
async void Handle_Clicked(object sender, System.EventArgs e)
{
await CrossMedia.Current.Initialize();
var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
{
Directory = "MyPhoto",
Name = "Nextflow.jpg",
SaveToAlbum = true
});
if (file == null)
return;
image.Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
file.Dispose();
return stream;
});
}
}
}
any help would be amazing!
Thanks in advance!