简体   繁体   中英

Cordova: InAppBrowser working on android emulator but not on android device

I'm trying to get InAppBrowser to launch a browser window from my app. When I try using my code on an Android emulator running from Visual Studio the browser launches as expected, but when I install an apk (built through Adobe PhoneGap build) to my Android device, I push the button and nothing occurs. I've verified that the event is indeed executing through an alert() on the device, but the browser isn't opening up. Any ideas?

HTML:

    <div class="app">
        <div>
            <input type="button" id="launch" value="Launch browser to www.google.com!"/>
        </div>
    </div>

JS:

(function () {
    "use strict";

    document.addEventListener( 'deviceready', onDeviceReady.bind( this ), false );

    function onDeviceReady() {
        // Handle the Cordova pause and resume events
        document.addEventListener( 'pause', onPause.bind( this ), false );
        document.addEventListener('resume', onResume.bind(this), false);
        document.querySelector('input#launch').addEventListener('click', launchGoogle);
    };

    function onPause() {
        // TODO: This application has been suspended. Save application state here.
    };

    function onResume() {
        // TODO: This application has been reactivated. Restore application state here.
    };
})();

function launchGoogle() {
    alert("launchGoogle()");
    cordova.InAppBrowser.open("http://www.google.com", "_blank", "location=yes");
}

I tried wrapping my call using a try statement and get the error " Cannot call method 'open' of undefined ". I assume this means the InAppBrowser plugin isn't getting installed.

Turns out the problem was the plugin wasn't being loaded. Reason: the plugins weren't being downloaded.

Turns out the plugins weren't being downloaded by PhoneGap Build. Reason: PhoneGap build needs your config.xml in the www/ directory, not in the root project directory as Visual Studio had it originally.

Copying the config.xml file to the www/ directory fixed the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM