Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom URL Schemes not supported #3479

Closed
hssm opened this issue Jul 28, 2015 · 14 comments
Closed

Custom URL Schemes not supported #3479

hssm opened this issue Jul 28, 2015 · 14 comments
Labels
Milestone

Comments

@hssm
Copy link
Member

hssm commented Jul 28, 2015

Originally reported on Google Code with ID 2583

The Android operating system supports Custom URL schemes, where by an application and
invoke services of another application.

The following example applies to the Pleco Chinese Dictionary application, which registers
itself as handling 'plecoapi://' URL scheme.

What steps will reproduce the problem?

1. Create a card with the following template text:

<a href="plecoapi://x-callback-url/s?q=考试">Test1</a>
<a href="javascript:window.location='plecoapi://x-callback-url/s?q=考试';">Test2</a>

2. View the card and click on either hyperlink.


What is the expected output? What do you see instead?

Clicking on either link should result in the registered handler of the custom URL scheme
to open.

However on the current version of Ankidroid, nothing happens when either link is clicked.


Does it happen again every time you repeat the steps above? Or did it
happen only one time?

Yep


Paste the "debug info" from the AnkiDroid "About" dialog below (see the
above help webpage for detailed instructions).

N/A


Please provide any additional information below.

Custom URL scheme can be tested using an Android web browser. I tested the following
file successfully with Firefox and Google Chrome:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<a href="plecoapi://x-callback-url/s?q=考试">Test1</a>
<a href="javascript:window.location='plecoapi://x-callback-url/s?q=考试';">Test2</a>
</body>
</html>

(Note that merely pasting the Custom URL into the Google Chrome search box does not
work.)

Reported by pross@xvid.org on 2015-04-16 07:56:46

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Does the intent:// syntax work?

https://developer.chrome.com/multidevice/android/intents

Reported by perceptualchaos2 on 2015-04-17 00:02:37

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

intent:// does not work either

<a href="intent://x-callback-url/s?q=好的#Intent;scheme=plecoapi;package=com.pleco.chinesesystem;end">Test3</a></br>

This href works on Google Chrome for Android. Firefox doesn't seem to have support
for it yet: https://bugzilla.mozilla.org/show_bug.cgi?id=851693

Reported by pross@xvid.org on 2015-04-17 01:50:41

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Hmm so absolutely nothing happens?

Reported by perceptualchaos2 on 2015-04-17 02:22:03

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

did you check that normal URLs are working properly?

Reported by perceptualchaos2 on 2015-04-17 02:23:37

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Correct, clicking on the intent:// link causes absolutely nothing to happen. There are
no error messages.

Normal http:// and https:// URLs work correctly. Clicking on them opens the default
web browser app. However email:// and data:// URLs do not work. Absolutely nothing
happens. ftp:// URLs cause Ankidroid to crash.

Just to clarify, I am inputting the HTML into the card template.

Below is another example that is app independent. Clicking on this link should open
your preferred mapping application and perform the query. This does not work in Ankidroid.

<a href="intent://?q=Yellow River#Intent;scheme=geo;action=android.intent.action.VIEW;category=android.intent.category.BROWSABLE;end">Yellow
River</a>

Reported by pross@xvid.org on 2015-04-17 07:10:12

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Would you be able to upload an example deck that we can use to test these cases? 

If you're interested in contributing a patch to fix this problem, a good place to look
would be the shouldOverrideUrlLoading() implementation in AbstractFlashcardViewer.java

Reported by perceptualchaos2 on 2015-04-17 08:08:14

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

If you're going to upload a deck then please use examples that don't require us to install
any 3rd party apps for it to work properly

Reported by perceptualchaos2 on 2015-04-17 08:12:54

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Thanks for pointing me in the right direction.

I have attached an example deck and patch. There is one card in the deck with all kinds
of hyperlinks. For testing I suggest using the geo:// hyperlink, as it is a  standard
(http://tools.ietf.org/html/rfc5870) and doesn't require 3rd party apps for testing.

The patch fixes three things.

1. The Java URL class was being used to exclude malformed URLs. However this class
doesn't know about the geo:// or anything more recent. I have removed the malformed
URL check, however it would be nice to know why it was added (git blame doesn't tell
me anything useful.)

2. ActivityNotFoundException was not being caught. This was causing URLs, that got
through the malformed URL check (e.g. ftp://) to crash Ankidroid.

3. data:// URLs were also being rejected by The Java URL class. I think they should
be treated like file:// URL.

With the patch applied you should be able to click on geo:// links and have the location
be displayed in your preferred mapping application. I tested this using the Android
Emulator (Android v5.0) and on my device (v4.2).

Finally note. On further reading, the intent:// syntax appears to be specific to Google
Chrome. This is not yet part of the WebView framework.

Reported by pross@xvid.org on 2015-04-17 14:05:04


- _Attachment: [0001-Support-Custom-URLs.patch](https://storage.googleapis.com/google-code-attachments/ankidroid/issue-2583/comment-8/0001-Support-Custom-URLs.patch)_ - _Attachment: [Custom URL Test Deck.apkg](https://storage.googleapis.com/google-code-attachments/ankidroid/issue-2583/comment-8/Custom URL Test Deck.apkg)_

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Thanks, would you be able to submit a pull request on github?

Reported by perceptualchaos2 on 2015-04-17 15:08:05

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Done.

Reported by pross@xvid.org on 2015-04-18 04:05:10

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Reported by Houssam.Salem.Au on 2015-04-23 05:55:10

  • Status changed: FixedInDev

@timrae timrae modified the milestone: v2.5 Release Jul 28, 2015
@timrae timrae closed this as completed Oct 28, 2015
@RichardHoOoOo
Copy link

Could I trouble you to shared the link of the pull request that fix this bug?

@RichardHoOoOo
Copy link

Sorry I missed the link in the attachment.

@timrae
Copy link
Member

timrae commented Jun 4, 2017

You might be interested in this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants