diff options
| author | Po Lu | 2023-07-10 13:31:57 +0800 |
|---|---|---|
| committer | Po Lu | 2023-07-10 13:31:57 +0800 |
| commit | cf2dde4261a311406203a38d6bf1be72b4f9e8a7 (patch) | |
| tree | 904aa8c47417f9c16018ed04bf7ef05bfd446268 /java | |
| parent | faca007b61422969f5c8888c67a1e356a8c5b64a (diff) | |
| download | emacs-cf2dde4261a311406203a38d6bf1be72b4f9e8a7.tar.gz emacs-cf2dde4261a311406203a38d6bf1be72b4f9e8a7.zip | |
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.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsService.java | 65 |
1 files changed, 45 insertions, 20 deletions
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 | |||
| 583 | } | 583 | } |
| 584 | } | 584 | } |
| 585 | 585 | ||
| 586 | /* Ask the system to open the specified URL. | 586 | /* Ask the system to open the specified URL in an application that |
| 587 | understands how to open it. | ||
| 588 | |||
| 589 | If SEND, tell the system to also open applications that can | ||
| 590 | ``send'' the URL (through mail, for example), instead of only | ||
| 591 | those that can view the URL. | ||
| 592 | |||
| 587 | Value is NULL upon success, or a string describing the error | 593 | Value is NULL upon success, or a string describing the error |
| 588 | upon failure. */ | 594 | upon failure. */ |
| 589 | 595 | ||
| 590 | public String | 596 | public String |
| 591 | browseUrl (String url) | 597 | browseUrl (String url, boolean send) |
| 592 | { | 598 | { |
| 593 | Intent intent; | 599 | Intent intent; |
| 594 | Uri uri; | 600 | Uri uri; |
| @@ -596,28 +602,47 @@ public final class EmacsService extends Service | |||
| 596 | try | 602 | try |
| 597 | { | 603 | { |
| 598 | /* Parse the URI. */ | 604 | /* Parse the URI. */ |
| 599 | uri = Uri.parse (url); | 605 | if (!send) |
| 600 | |||
| 601 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) | ||
| 602 | { | 606 | { |
| 603 | /* On Android 4.4 and later, check if URI is actually a | 607 | uri = Uri.parse (url); |
| 604 | file name. If so, rewrite it into a content provider | 608 | |
| 605 | URI, so that it can be accessed by other programs. */ | 609 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) |
| 606 | 610 | { | |
| 607 | if (uri.getScheme ().equals ("file") | 611 | /* On Android 4.4 and later, check if URI is actually |
| 608 | && uri.getPath () != null) | 612 | a file name. If so, rewrite it into a content |
| 609 | uri | 613 | provider URI, so that it can be accessed by other |
| 610 | = DocumentsContract.buildDocumentUri ("org.gnu.emacs", | 614 | programs. */ |
| 611 | uri.getPath ()); | 615 | |
| 616 | if (uri.getScheme ().equals ("file") | ||
| 617 | && uri.getPath () != null) | ||
| 618 | uri | ||
| 619 | = DocumentsContract.buildDocumentUri ("org.gnu.emacs", | ||
| 620 | uri.getPath ()); | ||
| 621 | } | ||
| 622 | |||
| 623 | Log.d (TAG, ("browseUri: browsing " + url | ||
| 624 | + " --> " + uri.getPath () | ||
| 625 | + " --> " + uri)); | ||
| 626 | |||
| 627 | intent = new Intent (Intent.ACTION_VIEW, uri); | ||
| 628 | intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK | ||
| 629 | | Intent.FLAG_GRANT_READ_URI_PERMISSION); | ||
| 612 | } | 630 | } |
| 631 | else | ||
| 632 | { | ||
| 633 | intent = new Intent (Intent.ACTION_SEND); | ||
| 634 | intent.setType ("text/plain"); | ||
| 635 | intent.putExtra (Intent.EXTRA_SUBJECT, "Sharing link"); | ||
| 636 | intent.putExtra (Intent.EXTRA_TEXT, url); | ||
| 637 | |||
| 638 | /* Display a list of programs able to send this URL. */ | ||
| 639 | intent = Intent.createChooser (intent, "Send"); | ||
| 613 | 640 | ||
| 614 | Log.d (TAG, ("browseUri: browsing " + url | 641 | /* Apparently flags need to be set after a choser is |
| 615 | + " --> " + uri.getPath () | 642 | created. */ |
| 616 | + " --> " + uri)); | 643 | intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); |
| 644 | } | ||
| 617 | 645 | ||
| 618 | intent = new Intent (Intent.ACTION_VIEW, uri); | ||
| 619 | intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK | ||
| 620 | | Intent.FLAG_GRANT_READ_URI_PERMISSION); | ||
| 621 | startActivity (intent); | 646 | startActivity (intent); |
| 622 | } | 647 | } |
| 623 | catch (Exception e) | 648 | catch (Exception e) |