URL Scheme:如何创建一个链接,该链接将在 Google Drive 应用程序中打开一个文档 [英] URL Scheme: How can I create a link, which will open a document in the Google Drive app

查看:11
本文介绍了URL Scheme:如何创建一个链接,该链接将在 Google Drive 应用程序中打开一个文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个网页,其中嵌入了多个 Google 文档.我的问题是,当在 android 设备上查看此页面时,用户会看到糟糕的基于网络的 Google Docs 编辑器.因此,我想在我的页面上有一个链接,它可以在用户手机上打开本地 Google Drive 应用程序,以便他/她可以在那里编辑文档.搜索了两个小时后,我无法弄清楚如何制作链接,该链接会自动在本机应用程序中打开文档.

I am trying to create a web page, which embeds several Google Docs in it. My problem is that when this page is viewed on an android device, then the user is presented with the terrible web based Google Docs editor. Therefore, I would like to have a link on my page, which opens the native Google Drive app on the users phone, so he/she can edit the document there. After searching for two hours, I am unable to figure out how to make a link, which automatically opens the document in the native app.

我使用以下链接在 google 市场中成功查看了 Google Drive 应用程序:

I succeeded with viewing the Google Drive app in google market using the following link:

market://details?id=com.google.android.apps.docs

market://details?id=com.google.android.apps.docs

我也尝试过

googledrive://no-idea-what-to-write-here

googledrive://no-idea-what-to-write-here

但这也没有成功.

这可能吗,还是仅适用于 iOS?

Is this possible at all, or does this only work on iOS?

推荐答案

似乎没有什么好方法可以做你想做的事(至少根据我对 Android 4.0.4 的测试;也许情况与其他版本).

There does not seem to be a good way to do what you want (at least according to my testing with Android 4.0.4; maybe the situation is different with other versions).

理论上,只需使用文档的 https://docs.google.com/... 链接即可.根据 这个关于 StackOverflow 的答案,拦截 http:https: URL 是从 Android 浏览器打开链接时启动应用程序的正确方法.Google Drive 应用正是这样做的——它为 https://drive.google.comhttps://docs.google.com 注册了意图过滤器https://spreadsheets.google.com 和一堆类似的 URL(包括具有相同主机名的 http:).这实际上是有效的——当使用普通的 Android 浏览器时,尝试打开一个指向 https://drive.google.com 的链接会导致选择器弹出列表中包含 Google Drive 应用程序(连同所有已安装的浏览器);选择 Google Drive 会根据需要在 Google Drive 编辑器中打开文档.

In theory, just using the https://docs.google.com/... link for the document should work for you. According to this answer on StackOverflow, intercepting http: or https: URLs is the proper way to start an app when opening a link from the Android browser. The Google Drive app does exactly this — it registers intent filters for https://drive.google.com, https://docs.google.com, https://spreadsheets.google.com and a bunch of similar URLs (including http: with the same host names). And this actually works — when using the stock Android browser, attempting to open a link pointing to https://drive.google.com results in the chooser popup with the Google Drive app included in the list (together with all installed browsers); selecting Google Drive results in opening the document in the Google Drive editor, as you want.

但问题是,这种被截获的 HTTP[S] URL只能在普通的 Android 浏览器中工作——我找不到任何第三方浏览器可以在关注时显示应用程序选择器这样的链接.我测试了 Chrome、Dolphin、Firefox、Light Browser、Opera(包括 Classic 和 Mini)、UC 浏览器,所有这些都只是在内部打开了链接,而不是提供将其传递给 Google Drive 应用程序.

But the problem is that such intercepted HTTP[S] URLs work only in the stock Android browser — I have not been able to find any third-party browser which could show the app chooser when following such links. I tested Chrome, Dolphin, Firefox, Light Browser, Opera (including Classic and Mini), UC Browser, and all of them just opened the link internally instead of offering to pass it to the Google Drive app.

还有另一种方法可以创建启动 Android 应用的链接——使用 intent: URI 方案.我无法找到 intent: URI 格式的适当文档;当然,生成此类 URI 的函数的源代码可用.

There is another way to make a link which starts an Android app — use the intent: URI scheme. I have not been able to find proper documentation for the intent: URI format; of course, the source code for the function which generates such URIs is available.

对于 您的测试文档:

https://docs.google.com/document/d/1zSzDnV-90Ke3dzCCJ2CZ6iQ3JQ3F1hL1udGDqbNwwbY/edit?usp=sharing

在 Google Drive 应用程序中打开它的相应 intent: 链接将是:

the corresponding intent: link which opens it in the Google Drive app will be:

intent://docs.google.com/document/d/1zSzDnV-90Ke3dzCCJ2CZ6iQ3JQ3F1hL1udGDqbNwwbY/edit?usp=sharing#Intent;scheme=https;action=android.intent.action.VIEW;category=android.intent.category.DEFAULT;category=android.intent.category.BROWSABLE;package=com.google.android.apps.docs;end

带有此 URI 的测试链接是在单独的页面上(此处无法创建指向此类 URI 的实际链接).

A test link with this URI is on a separate page (it is not possible to make an actual link pointing to such URI here).

转换过程如下:

  1. 将起始 https: 替换为 intent:.

附加意图参数:

#Intent;scheme=https;action=android.intent.action.VIEW;category=android.intent.category.DEFAULT;category=android.intent.category.BROWSABLE;package=com.google.android.apps.docs;end

这里的scheme=https对应原URL中的https:,所以如果要转换成纯http:的URL,这个字段应该是 scheme=http.package=com.google.android.apps.docs 是应处理链接的应用的包名称.

Here scheme=https correspond to https: in the original URL, so if you want to convert a plainhttp: URL, this field should be scheme=http. And package=com.google.android.apps.docs is the package name of the app which should handle the link.

现在,当点击此类链接时,浏览器应直接打开 Google Drive 应用程序(不显示应用程序选择器).但是,如果未安装该应用,Android 将改为打开 Market 应用,并搜索指定的包名称,以便用户安装所需的应用.

Now, when such link is followed, the browser should open the Google Drive app directly (without showing the app chooser). However, if the app is not installed, Android will open the Market app instead, and perform a search for the specified package name, so that the user could install the required app.

也可以在没有package参数的情况下制作intent:链接:

It is also possible to make the intent: link without the package parameter:

intent://docs.google.com/document/d/1zSzDnV-90Ke3dzCCJ2CZ6iQ3JQ3F1hL1udGDqbNwwbY/edit?usp=sharing#Intent;scheme=https;action=android.intent.action.VIEW;category=android.intent.category.DEFAULT;category=android.intent.category.BROWSABLE;end

在这种情况下,行为应该与在普通 Android 浏览器中跟踪截获的 https: 链接时的行为相同——将显示带有 Google Drive 应用和所有浏览器应用的应用选择器,如果未安装 Google Drive 应用,则不会重定向用户从 Market 安装它.

In this case the behavior should be the same as when the intercepted https: link is followed in the stock Android browser — the app chooser with the Google Drive app and all browser apps will be displayed, and if the Google Drive app is not installed, the user will not be redirected to install it from Market.

与截获的 http:https: 链接不同,intent: 链接适用于更广泛的 Android 浏览器应用程序;不幸的是,一些浏览器不支持它们.我的测试结果:

Unlike intercepted http: and https: links, intent: links work in a wider range of Android browser apps; unfortunately, some browsers do not support them. Results of my testing:

  • 作品:库存的 Android 4.0.4 浏览器、Chrome、Light Browser、Opera、Opera Classic.
  • 不工作:Dolphin、Firefox (功能请求待处理),UC 浏览器.
  • Works: stock Android 4.0.4 browser, Chrome, Light Browser, Opera, Opera Classic.
  • Does not work: Dolphin, Firefox (feature request is pending), UC Browser.

而且,显然,非 Android 浏览器根本不支持此类链接,因此如果您的页面也必须可供其他客户端使用,则您需要使用某种浏览器嗅探.

And, obviously, non-Android browsers would not support such links at all, so you will need to use some kind of browser sniffing if your pages also must be usable for other clients.

某些应用使用完全非标准的 URI 方案,这些方案也可能适用于第三方浏览器.但是,Google Drive 应用程序不这样做,因此该解决方案不适合它(除非有人创建了一个桥"应用程序,它只是将请求传递给 Google Drive 应用程序).

Some apps use completely nonstandard URI schemes, which might also work from third-party browsers. However, the Google Drive app does not do that, therefore this solution is not suitable for it (unless someone creates a "bridge" app which just passes requests to the Google Drive app).

出于安全考虑,一些浏览器也可能禁止非标准 URI 方案,除了一些列入白名单的方案(例如 market:);我没有尝试对此进行测试.

Some browsers could also disallow nonstandard URI schemes except some whitelisted ones (such as market:) due to security concerns; I did not try to test this.

这篇关于URL Scheme:如何创建一个链接,该链接将在 Google Drive 应用程序中打开一个文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆