@@ -58,7 +58,28 @@ static boolean isSharedTextAnUrl(String sharedText) {
5858 if (sharedText == null || sharedText .isEmpty ()) return false ;
5959
6060 return Patterns .WEB_URL .matcher (sharedText ).matches ()
61- || Pattern .matches ("magnet:\\ ?xt=urn:btih:.*?" , sharedText );
61+ || Pattern .matches ("magnet:\\ ?xt=urn:btih:.*?" , sharedText )
62+ || isNonFileUrlScheme (sharedText );
63+ }
64+
65+ /**
66+ * Check if the shared text is a URL with a non-file URI scheme that should be opened
67+ * with the url-opener script rather than saved as a file. (#3935)
68+ */
69+ static boolean isNonFileUrlScheme (String sharedText ) {
70+ try {
71+ Uri uri = Uri .parse (sharedText );
72+ String scheme = uri .getScheme ();
73+ if (scheme == null || scheme .isEmpty ()) return false ;
74+ if (UriScheme .SCHEME_CONTENT .equalsIgnoreCase (scheme ) || UriScheme .SCHEME_FILE .equalsIgnoreCase (scheme )) return false ;
75+ if (uri .getHost () != null && !uri .getHost ().isEmpty ()) return true ;
76+ return "mailto" .equalsIgnoreCase (scheme ) || "tel" .equalsIgnoreCase (scheme )
77+ || "irc" .equalsIgnoreCase (scheme ) || "ircs" .equalsIgnoreCase (scheme )
78+ || "gopher" .equalsIgnoreCase (scheme ) || "sftp" .equalsIgnoreCase (scheme )
79+ || "nfs" .equalsIgnoreCase (scheme ) || "smb" .equalsIgnoreCase (scheme );
80+ } catch (Exception e ) {
81+ return false ;
82+ }
6283 }
6384
6485 @ Override
@@ -79,7 +100,15 @@ protected void onResume() {
79100 final Uri sharedUri = intent .getParcelableExtra (Intent .EXTRA_STREAM );
80101
81102 if (sharedUri != null ) {
82- handleContentUri (sharedUri , sharedTitle );
103+ String sharedScheme = sharedUri .getScheme ();
104+ if (sharedScheme != null
105+ && !UriScheme .SCHEME_CONTENT .equals (sharedScheme )
106+ && !UriScheme .SCHEME_FILE .equals (sharedScheme )
107+ && sharedUri .getHost () != null && !sharedUri .getHost ().isEmpty ()) {
108+ handleUrlAndFinish (sharedUri .toString ());
109+ } else {
110+ handleContentUri (sharedUri , sharedTitle );
111+ }
83112 } else if (sharedText != null ) {
84113 if (isSharedTextAnUrl (sharedText )) {
85114 handleUrlAndFinish (sharedText );
0 commit comments