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.
This commit is contained in:
Po Lu 2023-06-01 16:31:50 +08:00
parent aed0a11147
commit 0014a10b24

View file

@ -62,6 +62,8 @@
import android.os.VibratorManager;
import android.os.VibrationEffect;
import android.provider.DocumentsContract;
import android.util.Log;
import android.util.DisplayMetrics;
@ -546,11 +548,33 @@ invocation of app_process (through android-emacs) can
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)