launchExternal doesn't work on XDK app on Andr

2019-07-25 13:06发布

I have an application that was developed in XDK. The app links to an external web site at one point (for a PDF actually).

I've tried both window.open(url,"_system") and intel.xdk.device.launchExternal(url) and both work on IOS and Android when using the Intel App Preview app.

However, once the build was completed and the app was uploaded to the Play store, the external links do not work. I can't say about IOS yet because Apple hasn't finished testing the app, but on Android, it's as though the link doesn't exist. There is no response at all. Even adding a try/catch loop didn't produce any more information.

I realize that because the link produces a PDF that the Android device has to have a PDF viewer installed to view it, however my testing device does have one, and as mentioned when run from App Preview, it downloads the PDF and prompts to view it in Adobe.

Any ideas? Is there a plugin I have to check off for Cordova options for launchExternal to work?

2条回答
太酷不给撩
2楼-- · 2019-07-25 13:13

In order to use intel.xdk.device.launchExternal(url), you are required to include the Device plugin under the Intel XDK Plugins group on the Projects Panel > Cordova 3.X Hybrid Mobile App Settings > Included Plugins > Featured & Custom Cordova Plugins > Device.

In order to use window.open(url,"_system") to open a URL leveraging the Cordova inAppBrowser plugin, you are required to include the In App Browser plugin on the Projects Panel > Cordova 3.X Hybrid Mobile App Settings > Included Plugins > Standard Cordova Plugins > In App Browser.

<!DOCTYPE html><!--HTML5 doctype-->
<html>
<head>
    <title>Your New Application</title>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0" />
    <style type="text/css">
        /* Prevent copy paste for all elements except text fields */
        *  { -webkit-user-select:none; -webkit-tap-highlight-color:rgba(255, 255, 255, 0); }
        input, textarea  { -webkit-user-select:text; }
        body { background-color:white; color:black }
    </style>
    <script src='intelxdk.js'></script>
    <script src='cordova.js'></script>
    <script src='xhr.js'></script>
    <script type="text/javascript">
        var onDeviceReady=function(){                             // called when Cordova is ready
           if( window.Cordova && navigator.splashscreen ) {     // Cordova API detected
                navigator.splashscreen.hide() ;                 // hide splash screen
            }
        } ;
        document.addEventListener("deviceready", onDeviceReady, false) ;
    </script>
</head>
<body>
    <!-- content goes here-->
    <h2>Hello World</h2>
    <script>
        function openExternal(elem) {
            window.open(elem.href, "_system");
            return false; // Prevent execution of the default onClick handler 
        }
    </script>
    <a href="https://www.twitter.com" onClick="javascript:return openExternal(this)">Twitter</a>
</body>
</html>
查看更多
【Aperson】
3楼-- · 2019-07-25 13:14

Please note that intel.xdk.device.launchExternal has now been deprecated. Use the default inappbrowser APi like this: window.open("market://details?id=","_blank","location=no")

查看更多
登录 后发表回答