私はXamarinフォームとVisual Studioを使用してモバイルAndroidアプリケーションを開発中です。Xamarinフォームは操作カメラが空の例外を返します
私はCrossMedia Pluginを使用して、自分のモバイルアプリで写真を撮ったり選択したりしています。最初は初期化に問題があり、その問題は誤ったAndroid SDKによって引き起こされたように見えました。 SDKを更新してすべてのパッケージを更新した後、「写真を選択」オプションを使用することができましたが、カメラを使用しても機能しません。何が原因であるか把握できません。
私は以下の方法を持っています。
private async void TakeAPhoto(object sender, EventArgs e)
{
try
{
await CrossMedia.Current.Initialize();
}
catch (Exception exception)
{
await DisplayAlert("ERROR", "Error initializing camera!", "Ok");
}
var cameraStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
var storageStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);
if (cameraStatus != PermissionStatus.Granted || storageStatus != PermissionStatus.Granted)
{
var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Camera, Permission.Storage });
cameraStatus = results[Permission.Camera];
storageStatus = results[Permission.Storage];
}
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
await DisplayAlert("No camera", "No camera available", "Ok");
return;
}
if (cameraStatus == PermissionStatus.Granted && storageStatus == PermissionStatus.Granted)
{
MediaFile file;
try
{
//Exception occurs in this code.
file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
{
//Specify Store to Album OR Directory, not both
Directory = "App_Images",
Name = "Test.jpg"
});
}
catch (Exception exception)
{
//I've got a break point here which is being hit, but the exception is (null)
throw;
}
if (file == null)
return;
//TODO: Store image to azure.
}
else
{
await DisplayAlert("Permissions Denied", "Unable to take photos.", "OK");
//On iOS you may want to send your user to the settings screen.
//CrossPermissions.Current.OpenAppSettings();
}
}
しかし、私はコードを実行しているときに空の例外が発生していますが、単に '(null)'と表示されます。
のVisual Studioのデバッグウィンドウは私に多くの情報が得られますが、私はここを参照してください唯一の本当の例外は「InvocationException」です。
InspectorDebugSession(0): HandleTargetEvent: TargetHitBreakpoint
InspectorDebugSession(0): StateChange: EntryPointBreakpointRegistered -> EntryPointBreakpointHit
InspectorDebugSession(0): AgentBridge.InjectAssembly: /mnt/shell/emulated/0/Android/data/MyFirstAppPackage.MyFirstAppPackage/files/.__override__/inspector-temp/Xamarin.Interactive.dll
InspectorDebugSession(0): AgentBridge.InjectAssembly: Mono.Debugger.Soft.InvocationException: Exception of type 'Mono.Debugger.Soft.InvocationException' was thrown.
at Mono.Debugger.Soft.InvocationsAPI.EndInvokeMethodInternalWithResultImpl(IAsyncResult asyncResult)
at Xamarin.Interactive.IdeSupport.AgentBridge.InjectAssembly(String agentAssemblyPath) in C:\d\lanes\4699\fec6f88f\source\xamarinvs\External\inspector-ide-integration\Xamarin.Interactive.IdeSupport\AgentBridge.cs:line 55
at Xamarin.Interactive.IdeSupport.InspectorDebuggerSession.<HandleTargetEvent>b__26_0(Object <p0>) in C:\d\lanes\4699\fec6f88f\source\xamarinvs\External\inspector-ide-integration\Xamarin.Interactive.IdeSupport\InspectorDebuggerSession.cs:line 242
InspectorDebugSession(0): StateChange: EntryPointBreakpointHit -> Error
InspectorDebugSession(0): Disposed
これを試してみるのにかなり時間が掛かりましたが、私は今この時点で完全に固執しています。また、私のコンピュータにSamsung Galaxy S4 Miniを接続してリモートデバッグを試みましたが、同じエラーが表示されます。私はここで間違って何をしていますか?
おそらくデバッグ用のアーティファクトです。私はすでに、モノ、エミュレータ/デバイスとビジュアルスタジオの組み合わせがこれより奇妙なことをするのを見た。 'throw'の代わりに' Debug.Write(exception.ToString()); ')を試してください。 – dlatikay
Androidエミュレータで問題なく機能を実行しました。 1つの関数に同じ名前の変数があることは既知の問題です。 2つの「例外」変数があります。 Chnage oneを「ex1」に設定すると、例外が表示されます。 –
ユリが言ったように、 'System.Exception'と' Java.Lang.Exception'の2種類の例外があります。あなたが使用している 'Exception'の型はわかりませんが、catchした例外は使用している' Exception'に属していないようです。 –