Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can cordova open app from http or https url?

I found many answers for a custom URL-Scheme like this (mycoolapp://somepath).

This plugin for example adds a custom URL-Sheme.*

But I don't want a custom URL-Scheme, I want a "normal" URL like this (http://www.mycoolapp.com/somepath).

If you open this in you Browser or click on a Hyperlink for example, then it should ask you to open my app (like google maps does it).

This question maybe already has an answer, but i can't find it.

If you don't know what I mean, that's how it should look if you click on the link to my website on an Android Device:

application link

Just with my app to select.

like image 471
Nano Avatar asked Jan 20 '15 09:01

Nano


People also ask

How does Cordova app work?

Cordova acts as a container for the app that you write using web technologies. When the app is compiled, your code actually stays intact. The compiler just takes your code and makes it available to the web view for rendering. If you've ever opened an HTML file in a browser, that's basically the same thing.

What browser does Cordova use?

Actually it is Chrome, but a different version from the Chrome App.

How do I open Cordova in InAppBrowser?

window.open = cordova.InAppBrowser.open; If you change the browsers window.open function this way, it can have unintended side effects (especially if this plugin is included only as a dependency of another plugin). The InAppBrowser window behaves like a standard web browser, and can't access Cordova APIs.

How can I get the parameter of a link in Cordova?

Open a website-link in a cordova app, and open a specific app-page and get the parameter of the link Related 3481 How can I check for an empty/undefined/null string in JavaScript?

Is it possible to open an app from a URL?

Some apple apps can be opened with a regular web url, but maybe they use some private API, I have not tested. – jcesarmobile Jan 20 '15 at 15:16 I think I want to do this ; so if they have my app it opens that, and if not it opens the website.

How to open PhoneGap app from unique domain URL?

How to open phonegap app from unique domain url? 0 Open a website-link in a cordova app, and open a specific app-page and get the parameter of the link Related


2 Answers

For the same problem I've used existing webintent plugin, modified the android manifest file - add those lines to activity

<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:host="example.com" android:scheme="http" />
</intent-filter>

and modified the index.html ondeviceready:

function deviceReady() {
    window.plugins.webintent.getUri(function(url) {
        console.log("INTENT URL: " + url);
        //...
    }); 
}

EDIT

I've just noticed a behavior which may be unwanted. When you open the app using the link (intent) from another application, it will (in many cases) create a new instance and not use the already running one (tested with gmail and skype). To prevent this a solution is to change Android Launch mode in config.xml file:

<preference name="AndroidLaunchMode" value="singleTask" />

(It works with cordova 3.5, not sure about the older version)

Then you need to add one more function to ondeviceready:

window.plugins.webintent.onNewIntent(function(url) {
    console.log("INTENT onNewIntent: " + url);
});

This one is triggered when the app was already running and was brought to front with intent.

like image 88
rhorvath Avatar answered Oct 19 '22 08:10

rhorvath


What you are looking for is called "Universal Links" on iOS and "Deep Linking" on Android.

And there is a Cordova plugin to handle that: https://www.npmjs.com/package/cordova-universal-links-plugin

like image 29
jwolinsky Avatar answered Oct 19 '22 08:10

jwolinsky