diff --git a/src/keepass2android/EntryEditActivity.cs b/src/keepass2android/EntryEditActivity.cs index 3faa9261..10c12f11 100644 --- a/src/keepass2android/EntryEditActivity.cs +++ b/src/keepass2android/EntryEditActivity.cs @@ -33,6 +33,7 @@ using KeePassLib.Security; using Android.Content.PM; using System.IO; using System.Globalization; +using Android.Database; using Android.Graphics; using Android.Util; using Debug = System.Diagnostics.Debug; @@ -523,14 +524,21 @@ namespace keepass2android String result = null; if (uri.Scheme.Equals("content")) { - var cursor = ContentResolver.Query(uri, null, null, null, null); + ICursor cursor = null; + try { + cursor = ContentResolver.Query(uri, null, null, null, null); + if (cursor != null && cursor.MoveToFirst()) { result = cursor.GetString(cursor.GetColumnIndex(OpenableColumns.DisplayName)); } } + catch (Exception e) + { + Kp2aLog.Log(e.ToString()); + } finally { if (cursor != null) @@ -621,8 +629,9 @@ namespace keepass2android //Android standard way to read the contents (content or file scheme) vBytes = ReadFully(ContentResolver.OpenInputStream(filename)); } - catch (Exception) + catch (Exception ex) { + Kp2aLog.Log(ex.ToString()); //if standard way fails, try to read as a file vBytes = File.ReadAllBytes(filename.Path); } diff --git a/src/keepass2android/Utils/Util.cs b/src/keepass2android/Utils/Util.cs index eba2c9f3..50c0cbf5 100644 --- a/src/keepass2android/Utils/Util.cs +++ b/src/keepass2android/Utils/Util.cs @@ -200,7 +200,7 @@ namespace keepass2android /// is more for one-time access, but therefore allows possibly more available sources. public static void ShowBrowseDialog(Activity activity, int requestCodeBrowse, bool forSaving, bool tryGetPermanentAccess) { - var loadAction = (tryGetPermanentAccess && IsKitKatOrLater) ? + var loadAction = IsKitKatOrLater ? Intent.ActionOpenDocument : Intent.ActionGetContent; if ((!forSaving) && (IsIntentAvailable(activity, loadAction, "*/*", new List { Intent.CategoryOpenable}))) {