URL scheme: how to create a link that opens a document in the Google Drive application

I am trying to create a webpage that includes several Google Docs. My problem is that when this page is viewed on an Android device, the user is provided with the terrible Google Docs web editor. Therefore, I would like to have a link on my page that opens its own Google Drive application on users' phones so that it can edit the document there. After searching for two hours, I canโ€™t figure out how to create a link that automatically opens a document in my own application.

I was able to view the Google Drive app in the Google market using the following link:

Market: // Details ID = com.google.android.apps.docs

I also experimented with

googledrive: // no-idea is what the record is here

But this also failed.

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

+4
source share
1 answer

There seems to be no good way to do what you want (at least according to my testing with Android 4.0.4, maybe the situation is different from other versions).

Using http: or https: links intercepted by the application

In theory, only using the https://docs.google.com/... link for the document should work for you. According to fooobar.com/questions/18380 / ... , grabbing the http: or https: URL is the right way to launch the application when opening the link in an Android browser. The Google Drive app does just that - it logs intent filters for https://drive.google.com , https://docs.google.com , https://spreadsheets.google.com and many similar URLs (including http: with the same hostnames). And it really works - when using the Android stock browser, an attempt to open a link pointing to https://drive.google.com leads to a pop-up of the selection with the Google Drive application included in the list (along with all installed browsers); Choosing Google Drive opens the document in the Google Drive editor as you want.

But the problem is that such intercepted HTTP [S] URLs only work in the Android browser in stock . I could not find a third-party browser that the application selector could show when it follows such links. I tested Chrome, Dolphin, Firefox, Light Browser, Opera (including Classic and Mini), UC Browser, and they all just opened the link inside, and did not offer to transfer it to the Google Drive application.

Using the intent: URI scheme intent:

There is another way to create a link that launches an Android application - use the intent: URI scheme intent: I could not find the correct documentation for the intent: format intent: URI; of course, source code is available for a function that generates such URIs .

For your test document :

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

the corresponding intent: link that opens in the Google Drive app will be as follows:

 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 

Test link with this URI on a separate page (it is impossible to specify the actual link pointing to such a URI here).

The conversion process is as follows:

  • Replace https: with intent:

  • Adding 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 corresponds to https: in the source URL, so if you want to translate a simple http: URL, this field should be scheme=http . And package=com.google.android.apps.docs is the name of the application package that should handle the link.

Now, when such a link is used, the browser should open the Google Drive application directly (without displaying the application selection). However, if the application is not installed, Android will open the Market application instead and search for the specified package name so that the user can install the necessary application.

It is also possible to make an 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 https: link was intercepted https: in the Android browser in the warehouse, an application application with the Google Drive application and all browser applications will appear, and if the Google Drive application is not installed, the user will not be redirected to install him with Market.

Unlike intercepted http: and https: links, intent: links work in a wider range of Android browser applications; Unfortunately, some browsers do not support them. The results of my testing:

  • Works: Android 4.0.4 browser, Chrome, Light Browser, Opera, Opera Classic.
  • Doesn't work: Dolphin, Firefox () UC Browser.

And, obviously, browsers that do not support Android will not support such links at all, so you will need to use some kind of browser scent if your pages should also be used for other clients.

Using a custom URI scheme

Some applications use completely non-standard URI schemes, which can also work in third-party browsers. However, the Google Drive application does not do this, so this solution is not suitable for it (unless someone creates a bridge application that simply transfers requests to the Google Drive application).

Some browsers may also prohibit non-standard URI schemes, except for some whitelists (for example, market: due to security problems; I did not try to verify this.

+10
source

Source: https://habr.com/ru/post/1490587/


All Articles