how can cordova open app from http or https url?

后端 未结 4 1537
刺人心
刺人心 2021-02-04 08:03

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

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-04 08:40

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

    
        
        
        
        
    
    

    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:

    
    

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

提交回复
热议问题