Firefox for Android does not launch app when link

2020-02-23 05:36发布

Firefox does not fire intents for clicked links the way it should. Therefore one cannot launch their app by clicking a link in Firefox (which is possible in Chrome and other browsers).

Edit: Please keep in mind that this is a post from 2013.

The desired behavior is the following: On my website I have a link, that when clicked should launch my Android app. If the app is not installed, preferably its page in Google Play should be opened to download it.

Method

The way I implement it is with an "intent URI" of the form: intent://myhost.com/#Intent;scheme=myscheme;package=com.myapp;end

In the app I register an intent filter in my manifest and listen for an intent that matches. However, it is up to the browser to fire such an intent when the link is clicked, so that my app can start.

I have tested this method with various browsers, and it works on most of them. With the notable exception of Firefox. With other browsers either my app launches, or its page in Google Play loads (in case it's not installed on the device).

The method with the "intent URI" is the recommended one by Google. It works perfectly on Chrome and on some other browsers. There are also other methods. I have read many threads and articles about the possibilities. The main alternatives are:

Alternative methods

  1. using a custom scheme, like myscheme://mywebsite.com
  2. using a regular http link, like http://mywebsite.com

Alternative 1 is not recommended for two reasons: - I do not own such a scheme, it does not exist globally, it's wrong. Google was also using market://... to start the Google Play app, but they have admitted that this is wrong and should change. - If my app is not currently installed, it will not be started and most browsers display an error page, which is obviously undesirable.

Alternative 2 does not work on most browsers and seems to be deprecated in favor of the "intent URI" method.

Firefox in particular

only works with the custom scheme (alternative 1). In the case of a regular http link (alternative 2) it just loads the link and shows the website. In the case of the recommended "intent URI" method, it does nothing. Actually, it shows a dialog asking whether you want to launch the app, but when you click Yes, nothing happens. So it seems Firefox recognizes links like "intent://..." but doesn't handle them properly.

Q: What is the recommended method for launching an app from a link in Firefox? Why isn't the "intent URI" method supported by Firefox?

Related links: https://developers.google.com/chrome/mobile/docs/intents https://stackoverflow.com/a/3472228/1045941 (keep in mind that the thread is quite old)

1条回答
祖国的老花朵
2楼-- · 2020-02-23 06:09

One option would be to add a hidden iframe, something like:

<iframe src="myscheme://..." style="visibility: hidden"></iframe>

It is tested to work on firefox, but it won't work on chrome. You probably want to use some user agent detection, here's an example: http://www.mazdigital.com/blog/post/2014/deep-links-on-mobile-browsers-demystified/

查看更多
登录 后发表回答