问题
I have tried the following markup but it does nothing
<ion-header-bar class="bar-dark">
<h1 class="title title-left">App Title</h1>
<a class="button rate-me button-light" href="amzn://apps/here">Rate</a>
</ion-header-bar>
I thought may be it is because no app to handle the intent is installed. So, I tried the following markup:
<ion-header-bar class="bar-dark">
<h1 class="title title-left">App Title</h1>
<a class="button rate-me button-light" href="http://link-to/app/here">Rate</a>
</ion-header-bar>
However, nothing happens on clicking on any of them on my android device. I can open the link when I try the app in my browser through. Do I need to add any permissions to make it work on android?
回答1:
Step1: Install inappbrowser plugin
plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git
or
cordova plugin add org.apache.cordova.inappbrowser
Step2: Insert the code in your view (html files)
<a class="item" onclick='window.open("https://www.google.com", "_system", "location=yes"); return false;'>Rate</a>
回答2:
I think the easiest way is to add target='_system'
to the <a>
element.
You will also need to install Cordova plugin InAppBrowser (org.apache.cordova.inappbrowser
).
Note however that if the app is missing, it will open the system web browser.
This opens the URL in the system web browser which asks the package manager for any apps using the URL scheme in their intent filters. WebView
does not do it on its own. If you want to do it in WebView
you need to override shouldOverrideUrlLoading
.
I just found out that the InAppBrowser does not handle <a>
tags at all since Cordova 3.4.0 or so. See: https://issues.apache.org/jira/browse/CB-6747 So you will need to work around it. Or you can just specify onclick="window.open('http://link-to/app/', '_system')"
in the anchor tag.
来源:https://stackoverflow.com/questions/39176713/how-can-i-open-another-app-using-intents-in-ionic