From 60c5bbc73d6dabccc6386011ea01ae7c85951ec6 Mon Sep 17 00:00:00 2001 From: ShirokaiLon <6662937+ShirokaiLon@users.noreply.github.com> Date: Tue, 22 Jan 2019 20:53:48 +0000 Subject: [PATCH] Handle exception when adding attachment that does not exist on file system. (#449) --- src/Android/MainActivity.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Android/MainActivity.cs b/src/Android/MainActivity.cs index 2f5dfa298..9b23d6c22 100644 --- a/src/Android/MainActivity.cs +++ b/src/Android/MainActivity.cs @@ -203,12 +203,19 @@ namespace Bit.Android return; } - using(var stream = ContentResolver.OpenInputStream(uri)) - using(var memoryStream = new MemoryStream()) + try { - stream.CopyTo(memoryStream); - MessagingCenter.Send(Xamarin.Forms.Application.Current, "SelectFileResult", - new Tuple(memoryStream.ToArray(), fileName ?? "unknown_file_name")); + using(var stream = ContentResolver.OpenInputStream(uri)) + using(var memoryStream = new MemoryStream()) + { + stream.CopyTo(memoryStream); + MessagingCenter.Send(Xamarin.Forms.Application.Current, "SelectFileResult", + new Tuple(memoryStream.ToArray(), fileName ?? "unknown_file_name")); + } + } + catch (Java.IO.FileNotFoundException) + { + return; } } }