Closed williambuchanan2 closed 1 year ago
Hi. Do you have a sample project? It works correctly for me
I pretty much copied the code as is (see below). I am on .net 7.0 - not sure if that makes a difference.
[RelayCommand]
public async void СapturePhotoPressed()
{
CancellationTokenSource cts = null;
try
{
DisposeItems();
if (!MediaGallery.CheckCapturePhotoSupport())
{
OperationInfo = "Capture Photo Not Supported";
return;
}
var status = await PermissionHelper.CheckAndRequest<Permissions.Camera>(
"The application needs permission to camera");
if (!status)
{
//Toast.ShowToast("The application did not get the necessary permission to camera");
return;
}
cts = new CancellationTokenSource(
TimeSpan.FromMilliseconds(DelayMilliseconds));
var file = await MediaGallery.CapturePhotoAsync(cts.Token);
SelectedItems = file != null ? new IMediaFile[] { file } : null;
SetInfo(SelectedItems);
}
catch (Exception ex)
{
OperationInfo = ex.Message;
}
finally
{
cts?.Dispose();
}
}
Do you have such a code?
public class MainActivity : MauiAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
NativeMedia.Platform.Init(this, savedInstanceState);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent intent)
{
if (NativeMedia.Platform.CheckCanProcessResult(requestCode, resultCode, intent))
NativeMedia.Platform.OnActivityResult(requestCode, resultCode, intent);
base.OnActivityResult(requestCode, resultCode, intent);
}
}
need more information
Description
When I call this line: var file = await MediaGallery.CapturePhotoAsync(cts.Token); The camera shows and I can click the tick, but the following code never gets executed. It is like the await never returns. Reported by another team member and verified same behaviour on my device.
Actual Behavior
Code never executes past this point.
Expected behavior
Code continues to execute.
Steps to reproduce the behavior
Screenshots or Videos
Reproduction Link
Configuration