From 0c6e2304fd278205045cb3bf1e8fcdd29ec595c5 Mon Sep 17 00:00:00 2001 From: serge Date: Fri, 2 Oct 2026 19:49:38 +0800 Subject: [PATCH] Keep the content URI when the picked file's path is not writable Pickers like the one of HyperOS ("Private access") also return the file path (_data). On Android 11+ a file of the shared storage is readable but not writable by its path, so the database opened read-only and asked to be copied, while the content URI itself grants writing. --- src/keepass2android-app/Utils/Util.cs | 4 +++- src/keepass2android-app/fileselect/FileSelectActivity.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/keepass2android-app/Utils/Util.cs b/src/keepass2android-app/Utils/Util.cs index 897f13bc7..fefc1ad16 100644 --- a/src/keepass2android-app/Utils/Util.cs +++ b/src/keepass2android-app/Utils/Util.cs @@ -539,7 +539,9 @@ public static string IntentToFilename(Intent data, Context ctx) c1.MoveToFirst(); var possibleFilename = c1.GetString(0); - if (File.Exists(possibleFilename)) + //the path only if it may be written: on Android 11+ a file of the shared storage is readable by its path but not + //writable (pickers like the one of HyperOS give the path too), while the content uri itself grants writing + if (File.Exists(possibleFilename) && new Java.IO.File(possibleFilename).CanWrite()) return possibleFilename; } } diff --git a/src/keepass2android-app/fileselect/FileSelectActivity.cs b/src/keepass2android-app/fileselect/FileSelectActivity.cs index ea8138ce4..7b395b557 100644 --- a/src/keepass2android-app/fileselect/FileSelectActivity.cs +++ b/src/keepass2android-app/fileselect/FileSelectActivity.cs @@ -422,7 +422,7 @@ protected override void OnActivityResult(int requestCode, Result resultCode, Int if ((resultCode == Result.Ok) && (requestCode == RequestCodeEditIoc)) { - string filename = Util.IntentToFilename(data, this); + string filename = Util.IntentToFilename(data, this) ?? data.DataString; LaunchPasswordActivityForIoc(IOConnectionInfo.FromPath(filename)); }