简体   繁体   English

用于从在三星浏览器/Firefox 等中不起作用但在 Chrome 中运行的链接打开应用程序的意图过滤器

[英]Intent filter for opening app from a link not working in Samsung Browser/Firefox etc. but working in Chrome

I have been experimenting with the Intent Filters for the past few hours, and I am really confused as to why the Google tutorial code for Handling App Links via Intent Filters is not working on my physical Samsung S8 devices's default Samsung browser or Firefox installed on it however working from the Google Chrome app.在过去的几个小时里,我一直在试验意图过滤器,我真的很困惑为什么通过意图过滤器处理应用程序链接的 Google 教程代码在我的物理三星 S8 设备的默认三星浏览器或安装在上面的 Firefox 上不起作用但是在 Google Chrome 应用程序中工作。

The code also works both in the default Android Studio Nexus 5's emulator default browser app as well as from Google Chrome.该代码也适用于默认的 Android Studio Nexus 5 模拟器默认浏览器应用程序以及 Google Chrome。

Here is the relevant code I have in the AndroidManifest.xml of the bare-bones app I am trying to diagnose the problem with:这是我试图诊断问题的准系统应用程序的AndroidManifest.xml中的相关代码:

<intent-filter">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="http" />
    <data android:scheme="https" />
    <data android:host="www.android.com"  />
</intent-filter>

What I am doing to test:我正在做什么来测试:

I click on a link for https://www.android.com from a search results page on Google.我从 Google 的搜索结果页面单击https://www.android.com的链接。

I expect to see a open with dialog with my test apps name however it does not show when I try this from anything but the the google chrome browser (and the Nexus 5 emulators default browser) it just automatically shows the webpage with no popup dialog.我希望看到一个带有我的测试应用程序名称的打开对话框,但是当我从 google chrome 浏览器(和 Nexus 5 模拟器默认浏览器)之外的任何东西尝试这个时它不会显示它只是自动显示没有弹出对话框的网页。

NB I have tried also tried the following things so far to no avail:注意,到目前为止,我也尝试过以下操作无济于事:

  • Changing the first line to <intent-filter android:autoVerify="true">将第一行更改为<intent-filter android:autoVerify="true">
  • Adding the line <data android:host="www.android.com/" /> in case the the problem has anything to do with the / at the end of URL.添加行<data android:host="www.android.com/" />以防问题与 URL 末尾的/有关。
  • Clearing the both browsers data/storage & generally resetting it.清除两个浏览器的数据/存储并通常重置它。

Does anyone know why this is happening / how to fix this?有谁知道为什么会这样/如何解决这个问题?

The browsers itself need to support and implment the browsability.浏览器本身需要支持和实现可浏览性。 The browsers have to find other activities supporting android.intent.category.BROWSABLE when opening a web-page.打开网页时,浏览器必须找到其他支持android.intent.category.BROWSABLE活动。

Firefox implements a less invasive experience to the user. Firefox 为用户提供了一种侵入性较小的体验。 When an url is opened which has a deep link to an app, the url bar displays a page action with a little Android head.当打开一个带有应用程序深层链接的 url 时,url 栏会显示一个带有小 Android 头的页面操作。 Clicking on this one will open the link with an Android activity other than a browser.单击此按钮将打开带有浏览器以外的 Android 活动的链接。

The behavior of the Android browser and Chrome you observed and made your expectation.您观察到的 Android 浏览器和 Chrome 的行为并做出了您的期望。 So nothing to add to this.所以没有什么可以补充的。

I'm not sure if I can fully talk about the Samsung browser, because the versions I have on my devices might be somehow outdated;我不确定我是否可以完整地谈论三星浏览器,因为我设备上的版本可能已经过时了; but I couldn't make it work with these at all.但我根本无法让它与这些一起工作。

The android:autoVerify attribute only makes the app the default on installation. android:autoVerify属性仅使应用程序成为安装时的默认设置。 android:host="www.android.com/" is just wrong, because / is the path and not part of the host. android:host="www.android.com/"是错误的,因为/是路径而不是主机的一部分。

You can fix this by go to Samsung Browser setting > Useful features > Open links in other apps您可以通过转到三星浏览器设置 > 有用功能 > 在其他应用程序中打开链接来解决此问题在此处输入图片说明

This may be late for you but hope it will help others.这对你来说可能晚了,但希望它会帮助其他人。

Opening the app for certain links only仅为某些链接打开应用程序

<intent-filter>
  <action android:name="android.intent.action.VIEW"></action>
  <category android:name="android.intent.category.DEFAULT"></category>
  <category android:name="android.intent.category.BROWSABLE"></category>
  <data android:scheme="spuul"></data>
</intent-filter>

With this, all URI's like spuul://movies/123 will be openend by the app.有了这个,所有 URI 像 spuul://movies/123 将被应用程序打开。 The app is then able to handle this URI and launch the correct content.然后,该应用程序能够处理此 URI 并启动正确的内容。 The link to Google Play like market://details?id=com.spuul.android. Google Play 的链接,如 market://details?id=com.spuul.android。

Fallback to market if app is not installed如果未安装应用程序,则回退到市场

<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:scheme="http" android:host="android.app.spuul.com" android:pathPrefix=""></data>
</intent-filter>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM