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

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

问题描述

我正在尝试创建一个网页,其中嵌入了多个 Google 文档.我的问题是,当在 android 设备上查看此页面时,用户会看到基于 Web 的糟糕的 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 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 云端硬盘会根据需要在 Google 云端硬盘编辑器中打开文档.

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 云端硬盘应用.

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. intent: 替换起始 https:.

附加意图参数:

#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 云端硬盘应用,则不会重定向用户以从电子市场安装该应用.

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 云端硬盘应用不会这样做,因此该解决方案不适合它(除非有人创建了一个桥接"应用,该应用只会将请求传递给 Google 云端硬盘应用).

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天全站免登陆