简体   繁体   English

Phonegap:InAppBrowser v0.5.4插件在Android中不起作用(Cordova v3.6.4)

[英]Phonegap: InAppBrowser v0.5.4 plugin not working in Android (Cordova v3.6.4)

I'm using cordova InAppBrowser plugin inside my app. 我在我的应用程序中使用cordova InAppBrowser插件 I installed the plugin using this code: 我使用以下代码安装了插件:

cordova plugin add org.apache.cordova.inappbrowser

What I want from the InAppBrowser plugin is, I want all external links inside my app side nav to be opened inside device browser. 我想从InAppBrowser插件获得的是,我希望在应用程序浏览器中的所有外部链接都在设备浏览器中打开。 Not inside the app. 不在应用内。

It's working perfectly for me when I tested it using Phonegap Developer App and phonegap serve command. 当我使用Phonegap Developer应用程序和phonegap serve命令对其进行测试时,它对我来说是完美的。

But, when I export an APK of it and installed it on the same device, the InAppBrowser plugin didn't open external links inside the browser. 但是,当我导出它的APK并将其安装在同一设备上时,InAppBrowser插件没有打开浏览器内部的外部链接。 Nothing happened when I clicked on the links. 单击链接没有任何反应。

My config.xml file: 我的config.xml文件:

<widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0" id="com.zulhilmizainudin.webhostingbandwidthcalculator" version="1.0.0">
  <name>WebHostingBandwidthCalculator</name>
  <description>Hello World sample application that responds to the deviceready event.</description>
  <author href="http://phonegap.com" email="support@phonegap.com">PhoneGap Team</author>
  <feature name="http://api.phonegap.com/1.0/device"/>
  <preference name="permissions" value="none"/>
  <preference name="orientation" value="default"/>
  <preference name="target-device" value="universal"/>
  <preference name="fullscreen" value="true"/>
  <preference name="webviewbounce" value="true"/>
  <preference name="prerendered-icon" value="true"/>
  <preference name="stay-in-webview" value="false"/>
  <preference name="ios-statusbarstyle" value="black-opaque"/>
  <preference name="detect-data-types" value="true"/>
  <preference name="exit-on-suspend" value="false"/>
  <preference name="show-splash-screen-spinner" value="true"/>
  <preference name="auto-hide-splash-screen" value="true"/>
  <preference name="disable-cursor" value="false"/>
  <preference name="android-minSdkVersion" value="7"/>
  <preference name="android-installLocation" value="auto"/>
  <icon src="icon.png"/>
  <icon src="res/icon/android/icon-36-ldpi.png" gap:platform="android" gap:density="ldpi"/>
  <icon src="res/icon/android/icon-48-mdpi.png" gap:platform="android" gap:density="mdpi"/>
  <icon src="res/icon/android/icon-72-hdpi.png" gap:platform="android" gap:density="hdpi"/>
  <icon src="res/icon/android/icon-96-xhdpi.png" gap:platform="android" gap:density="xhdpi"/>
  <icon src="res/icon/blackberry/icon-80.png" gap:platform="blackberry"/>
  <icon src="res/icon/blackberry/icon-80.png" gap:platform="blackberry" gap:state="hover"/>
  <icon src="res/icon/ios/icon-57.png" gap:platform="ios" width="57" height="57"/>
  <icon src="res/icon/ios/icon-72.png" gap:platform="ios" width="72" height="72"/>
  <icon src="res/icon/ios/icon-57-2x.png" gap:platform="ios" width="114" height="114"/>
  <icon src="res/icon/ios/icon-72-2x.png" gap:platform="ios" width="144" height="144"/>
  <icon src="res/icon/webos/icon-64.png" gap:platform="webos"/>
  <icon src="res/icon/windows-phone/icon-48.png" gap:platform="winphone"/>
  <icon src="res/icon/windows-phone/icon-173.png" gap:platform="winphone" gap:role="background"/>
  <gap:splash src="res/screen/android/screen-ldpi-portrait.png" gap:platform="android" gap:density="ldpi"/>
  <gap:splash src="res/screen/android/screen-mdpi-portrait.png" gap:platform="android" gap:density="mdpi"/>
  <gap:splash src="res/screen/android/screen-hdpi-portrait.png" gap:platform="android" gap:density="hdpi"/>
  <gap:splash src="res/screen/android/screen-xhdpi-portrait.png" gap:platform="android" gap:density="xhdpi"/>
  <gap:splash src="res/screen/blackberry/screen-225.png" gap:platform="blackberry"/>
  <gap:splash src="res/screen/ios/screen-iphone-portrait.png" gap:platform="ios" width="320" height="480"/>
  <gap:splash src="res/screen/ios/screen-iphone-portrait-2x.png" gap:platform="ios" width="640" height="960"/>
  <gap:splash src="res/screen/ios/screen-ipad-portrait.png" gap:platform="ios" width="768" height="1024"/>
  <gap:splash src="res/screen/ios/screen-ipad-landscape.png" gap:platform="ios" width="1024" height="768"/>
  <gap:splash src="res/screen/windows-phone/screen-portrait.jpg" gap:platform="winphone"/>
  <access origin="*" browserOnly="true"/>
  <gap:plugin name="org.apache.cordova.inappbrowser" />
</widget>

My question : 我的问题

How to make the InAppBrowser plugin working for the production version (APK)? 如何使InAppBrowser插件适用于正式版(APK)?

Note : 注意事项

I'm using cordova v3.6.4 for this project. 我正在为此项目使用cordova v3.6.4。

Solve. 解决。 I downgrade the InAppBrowser from v0.5.4 to v0.2.4 . 我将InAppBrowser的版本从v0.5.4降级到v0.2.4

First, I remove the v.0.5.4 plugin using this command: 首先,我使用以下命令删除v.0.5.4插件:

cordova plugin rm org.apache.cordova.inappbrowser

Then, I add v0.2.4 plugin using this command: 然后,我使用以下命令添加v0.2.4插件:

cordova plugin add org.apache.cordova.inappbrowser@0.2.4

Finally, I update my config.xml file: 最后,我更新了config.xml文件:

<access origin="*" />
<gap:plugin name="org.apache.cordova.inappbrowser" version="0.2.4" />

It's now working perfectly on Android 4.1.1! 现在可以在Android 4.1.1上完美运行了!

The problem is this line in your config.xml 问题是您的config.xml中的这一行

<access origin="*" browserOnly="true"/>

You need to add additional lines for the external domains you want to allow to be opened in external links. 您需要为要允许在外部链接中打开的外部域添加其他行。 For example if you want to allow google links to open in an external browser 例如,如果您想允许Google链接在外部浏览器中打开

<access origin="*twitter.*" launch-external="yes" />

Then you may also need to prevent the default action from happening when links are clicked. 然后,您可能还需要防止单击链接时发生默认操作。 I like this sort of code to open the links it depends on your links having a proper href and also all your external links having class="external" 我喜欢这种代码来打开链接,它取决于您的链接具有适当的href以及所有外部链接具有class="external"

jQuery(document).delegate('.external', 'click', function (e) {
    window.open(e.target.href, '_system');
    e.preventDefault();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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