[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/android 0014a10b242: Correctly export file:// URIs on Android
From: |
Po Lu |
Subject: |
feature/android 0014a10b242: Correctly export file:// URIs on Android |
Date: |
Thu, 1 Jun 2023 04:32:23 -0400 (EDT) |
branch: feature/android
commit 0014a10b242bac62b0ba913a5ee4da4cfbe07f41
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
Correctly export file:// URIs on Android
* java/org/gnu/emacs/EmacsService.java (browseUrl): If uri's
scheme is `file', rewrite it into a content URI.
---
java/org/gnu/emacs/EmacsService.java | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/java/org/gnu/emacs/EmacsService.java
b/java/org/gnu/emacs/EmacsService.java
index 2f35933a7d1..dde60e1c5af 100644
--- a/java/org/gnu/emacs/EmacsService.java
+++ b/java/org/gnu/emacs/EmacsService.java
@@ -62,6 +62,8 @@ import android.os.Vibrator;
import android.os.VibratorManager;
import android.os.VibrationEffect;
+import android.provider.DocumentsContract;
+
import android.util.Log;
import android.util.DisplayMetrics;
@@ -546,11 +548,33 @@ public final class EmacsService extends Service
browseUrl (String url)
{
Intent intent;
+ Uri uri;
try
{
- intent = new Intent (Intent.ACTION_VIEW, Uri.parse (url));
- intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
+ /* Parse the URI. */
+ uri = Uri.parse (url);
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
+ {
+ /* On Android 4.4 and later, check if URI is actually a
+ file name. If so, rewrite it into a content provider
+ URI, so that it can be accessed by other programs. */
+
+ if (uri.getScheme ().equals ("file")
+ && uri.getPath () != null)
+ uri
+ = DocumentsContract.buildDocumentUri ("org.gnu.emacs",
+ uri.getPath ());
+ }
+
+ Log.d (TAG, ("browseUri: browsing " + url
+ + " --> " + uri.getPath ()
+ + " --> " + uri));
+
+ intent = new Intent (Intent.ACTION_VIEW, uri);
+ intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK
+ | Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity (intent);
}
catch (Exception e)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- feature/android 0014a10b242: Correctly export file:// URIs on Android,
Po Lu <=