}
}
- /* 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;
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)
(function-put 'browse-url-default-haiku-browser
'browse-url-browser-kind 'external)
+(defcustom browse-url-android-share nil
+ "If non-nil, share URLs instead of opening them.
+When non-nil, `browse-url-default-android-browser' will try to
+share the URL being browsed through programs such as mail clients
+and instant messengers instead of opening it in a web browser."
+ :type 'boolean
+ :version "30.1")
+
(declare-function android-browse-url "androidselect.c")
;;;###autoload
(defun browse-url-default-android-browser (url &optional _new-window)
"Browse URL with the system default browser.
-Default to the URL around or before point."
+If `browse-url-android-share' is non-nil, try to share URL using
+an external program instead. Default to the URL around or before
+point."
(interactive (browse-url-interactive-arg "URL: "))
- (setq url (browse-url-encode-url url))
+ (unless browse-url-android-share
+ ;; The URL shouldn't be encoded if it's being shared through
+ ;; another program.
+ (setq url (browse-url-encode-url url)))
;; Make sure the URL starts with an appropriate scheme.
(unless (string-match "\\(.+\\):/" url)
(setq url (concat "http://" url)))
- (android-browse-url url))
+ (android-browse-url url browse-url-android-share))
(function-put 'browse-url-default-android-browser
'browse-url-browser-kind 'external)
FIND_METHOD (get_screen_height, "getScreenHeight", "(Z)I");
FIND_METHOD (detect_mouse, "detectMouse", "()Z");
FIND_METHOD (name_keysym, "nameKeysym", "(I)Ljava/lang/String;");
- FIND_METHOD (browse_url, "browseUrl", "(Ljava/lang/String;)"
+ FIND_METHOD (browse_url, "browseUrl", "(Ljava/lang/String;Z)"
"Ljava/lang/String;");
FIND_METHOD (restart_emacs, "restartEmacs", "()V");
FIND_METHOD (update_ic, "updateIC",
/* Other miscellaneous functions. */
-/* Ask the system to start browsing the specified encoded URL. Upon
- failure, return a string describing the error. Else, value is
- nil. */
+/* Ask the system to start browsing the specified URL. Upon failure,
+ return a string describing the error. Else, value is nil. URL
+ should be encoded unless SEND.
+
+ If SEND, open the URL with applications that can ``send'' or
+ ``share'' the URL (through mail, for example.) */
Lisp_Object
-android_browse_url (Lisp_Object url)
+android_browse_url (Lisp_Object url, Lisp_Object send)
{
jobject value, string;
Lisp_Object tem;
value = (*android_java_env)->CallObjectMethod (android_java_env,
emacs_service,
service_class.browse_url,
- string);
+ string,
+ (jboolean) !NILP (send));
android_exception_check ();
ANDROID_DELETE_LOCAL_REF (string);
int temperature;
};
-extern Lisp_Object android_browse_url (Lisp_Object);
+extern Lisp_Object android_browse_url (Lisp_Object, Lisp_Object);
extern int android_query_battery (struct android_battery_state *);
extern void android_display_toast (const char *);
}
DEFUN ("android-browse-url", Fandroid_browse_url,
- Sandroid_browse_url, 1, 1, 0,
- doc: /* Start the system web browser.
-Then, point the web browser to URL, which should be a URL-encoded
-URL with a scheme specified. Signal an error upon failure. */)
- (Lisp_Object url)
+ Sandroid_browse_url, 1, 2, 0,
+ doc: /* Open URL in an external application. URL should be a
+URL-encoded URL with a scheme specified unless SEND is non-nil.
+Signal an error upon failure.
+
+If SEND is nil, start a program that is able to display the URL, such
+as a web browser. Otherwise, try to share URL using programs such as
+email clients. */)
+ (Lisp_Object url, Lisp_Object send)
{
Lisp_Object value;
error ("No Android display connection!");
CHECK_STRING (url);
- value = android_browse_url (url);
+ value = android_browse_url (url, send);
/* Signal an error upon failure. */
if (!NILP (value))