网址方案:如何创建链接,以便在Google云端硬盘应用中打开文档 [英] URL Scheme: How can I create a link, which will open a document in the Google Drive app

查看:635
本文介绍了网址方案:如何创建链接,以便在Google云端硬盘应用中打开文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个网页,其中嵌入了多个Google文档。我的问题是,当在Android设备上查看此页面时,用户会看到可怕的基于Web的Google文档编辑器。因此,我希望在我的网页上建立一个链接,在用户手机上打开本机Google云端硬盘应用,以便他/她可以在此处编辑文档。搜索了两个小时后,我无法弄清楚如何创建链接,该链接会自动在本机应用程序中打开文档。



成功查看Google云端硬盘应用在谷歌市场使用以下链接:


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

我也尝试过使用


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


但是这也没有成功。



这是可能的吗,还是只能在iOS上使用?

解决方案

(至少根据我对Android 4.0.4的测试,可能情况与其他版本不同)。



使用 http: https:由应用拦截的链接



理论上,只需使用 https://docs.google.c om /... 文档的链接应该适合您。根据 StackOverflow上的此答案,拦截 http: https:从Android浏览器打开链接时,URLs是启动应用程序的正确方法。 Google云端硬盘应用正是如此 - 为 https://drive.google.com https://docs.google注册意图过滤器。 com https://spreadsheets.google.com 和一堆类似的网址(包括 http:具有相同的主机名)。这实际上是有效的 - 当使用股票Android浏览器时,尝试打开指向 https://drive.google.com 的链接会导致Google Drive的选择器弹出包含在列表中的应用程序(连同所有安装的浏览器);您可以根据需要选择Google Drive结果打开Goog​​le Drive编辑器中的文档。



但问题是,截获的HTTP [S]网址仅适用于在股票Android浏览器 - 我无法找到任何第三方浏览器可以显示应用程序选择器时,遵循此类链接。我测试了Chrome,Dolphin,Firefox,轻量级浏览器,Opera(包括Classic和Mini),UC浏览器,并且它们都在内部打开链接,而不是将其传递到Google Drive应用。



使用 intent: URI方案



还有另一种制作链接的方法它启动一个Android应用程序 - 使用 intent: URI方案。我一直无法找到 intent: URI格式的正确文档;当然,产生这种URI的函数的源代码是可用的。



对于您的测试文档

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

相应的 intent:链接会在Google云端硬盘应用中打开它:

  intent://docs.google.com/document/d/1zSzDnV-90Ke3dzCCJ2CZ6iQ3JQ3F1hL1udGDqbNwwbY/edit?usp = sharing#Intent;方案= https和行动= android.intent.action.VIEW;类别= android.intent.category.DEFAULT; CATEG ory = android.intent.category.BROWSABLE; package = com.google.android.apps.docs; end 

使用此URI的测试链接是单独页面(这是不可能的实际链接指向这样的URI)。

转换的过程如下:


  1. intent替换开始的 https: p>


  2. 追加意图参数:

      #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 对应于 https: 在原始URL中,所以如果你想转换一个简单的 http: URL,这个字段应该是 scheme = http 。并且 package = com.google.android.apps.docs 是应该处理链接的应用的包名称


现在,当遵循这样的链接时,浏览器应直接打开Goog​​le Drive应用程序(不显示应用程序选择器)。但是,如果未安装该应用程序,则Android将打开Market应用程序,并执行搜索指定的软件包名称,以便用户可以安装所需的应用程序。



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

  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云端硬盘应用和所有浏览器应用都会显示,如果未安装Google云端硬盘应用,用户将不会被重定向到Market安装。



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


  • 作品:支持Android 4.0.4浏览器,Chrome,Light Browser,Opera,Opera Classic。

  • 不起作用:Dolphin,Firefox(功能请求未决),UC浏览器。



显然, Android浏览器根本不支持这样的链接,因此如果您的网页也必须可用于其他客户端,您将需要使用某种浏览器嗅探。



使用自定义URI方案



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

由于安全考虑,一些浏览器也可能会禁止非标准URI方案,除了一些白名单的方案(例如 market:)。我没有试图测试这个。


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.

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

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

I also experimented with

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

But that did not succeed either.

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

解决方案

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).

Using http: or https: links intercepted by an app

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.

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.

Using the intent: URI scheme

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.

For your test document:

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

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

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).

The process of conversion is as follows:

  1. Replace starting https: with intent:.

  2. Append intent parameters:

    #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
    

    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.

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.

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

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.

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:

  • Works: stock Android 4.0.4 browser, Chrome, Light Browser, Opera, Opera Classic.
  • Does not work: Dolphin, Firefox (feature request is pending), UC Browser.

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.

Using a custom URI scheme

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).

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.

这篇关于网址方案:如何创建链接,以便在Google云端硬盘应用中打开文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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