From cf2dde4261a311406203a38d6bf1be72b4f9e8a7 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Mon, 10 Jul 2023 13:31:57 +0800 Subject: Update Android port * java/org/gnu/emacs/EmacsService.java (browseUrl): New argument SEND. Choose from a list of applications that want to share the URL if true. * lisp/net/browse-url.el (browse-url-android-share): New user option. (browse-url-default-android-browser): Respect said user option. * src/android.c (android_init_emacs_service) (android_browse_url): Expose new option. * src/android.h: Update prototypes. * src/androidselect.c (Fandroid_browse_url): Likewise. --- java/org/gnu/emacs/EmacsService.java | 65 +++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 20 deletions(-) (limited to 'java/org/gnu') diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java index 0543c3a1bdd..22649167f8a 100644 --- a/java/org/gnu/emacs/EmacsService.java +++ b/java/org/gnu/emacs/EmacsService.java @@ -583,12 +583,18 @@ public final class EmacsService extends Service } } - /* Ask the system to open the specified URL. + /* Ask the system to open the specified URL in an application that + understands how to open it. + + If SEND, tell the system to also open applications that can + ``send'' the URL (through mail, for example), instead of only + those that can view the URL. + Value is NULL upon success, or a string describing the error upon failure. */ public String - browseUrl (String url) + browseUrl (String url, boolean send) { Intent intent; Uri uri; @@ -596,28 +602,47 @@ public final class EmacsService extends Service try { /* Parse the URI. */ - uri = Uri.parse (url); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) + if (!send) { - /* 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 ()); + 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); } + else + { + intent = new Intent (Intent.ACTION_SEND); + intent.setType ("text/plain"); + intent.putExtra (Intent.EXTRA_SUBJECT, "Sharing link"); + intent.putExtra (Intent.EXTRA_TEXT, url); + + /* Display a list of programs able to send this URL. */ + intent = Intent.createChooser (intent, "Send"); - Log.d (TAG, ("browseUri: browsing " + url - + " --> " + uri.getPath () - + " --> " + uri)); + /* Apparently flags need to be set after a choser is + created. */ + intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); + } - 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) -- cgit v1.2.1