Search code examples
androidphonegap-buildphonegapinappbrowser

phonegap open link in app browser does not work


I build an Android APP by PhoneGap Build service(https://build.phonegap.com/apps)

I already add these into the config.xml

<plugin name="cordova-plugin-inappbrowser"/>
<access origin="*"/>
<access origin="tel:*" launch-external="yes"/>
<access origin="sms:*" launch-external="yes"/>
<plugin name="cordova-plugin-whitelist"/>
<allow-intent href="http:///"/>
<allow-intent href="https:///"/>
<allow-intent href="tel:*"/>
<allow-intent href="sms:*"/>
<allow-intent href="mailto:*"/>
<allow-intent href="geo:*"/>

And also add these to my HTML file

<script>
    document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady() {
        window.open = cordova.InAppBrowser.open;
    }
</script>

Finally...I have tried

<a href="#" onclick="cordova.InAppBrowser.open('https://www.google.com/', '_system');return false;">link</a>

and

<a href="#" onclick="window.open('https://www.google.com/', '_system');return false;">link</a>

I also tried the option 'location=yes' which I found in some answers

But all of them don't work....Do I miss any step?

PhoneGap Android version: cli-6.5.0, 6.1.2 and Android version: 7.1.1


Solution

  • I faced the same issue. But after struggling a lot this is what fixed my issue.

    First remove and re-add the InAppBrowser plugin,

    cordova plugin remove cordova-plugin-inappbrowser
    
    cordova plugin add cordova-plugin-inappbrowser
    

    Then add the following to your config.xml,

    <feature name="InAppBrowser">
        <param name="android-package" value="org.apache.cordova.InAppBrowser" />
    </feature>
    

    Remember by this time, InAppBrowser have to be in your plugins folder.

    Then the anchor tags in your app should look like,

    <a id="to-recover" href="#" onclick="cordova.InAppBrowser.open('https://www.google.com', '_system', 'location=yes');" >google</a>
    

    Note: Due to a bug in Cordova Android 7.1.3, InAppBrowser doesn't work. Maybe that is the issue affecting you. So stick with either Cordova Android 7.1.2 or upgrade to 7.1.4

    Reference:

    Android Class Not Found

    Plugin doesn't install correctly

    You can specify the Cordova Android version while installing like this,

    cordova platform add android@7.1.4