这篇文章主要介绍了html5打开本地app应用的方法,如果你的手机上安装有支付宝,那么在访问支付宝手机网页时就会自动打开支付宝app,否则在页面上会提示你进行下载app,这是如何实现的?感兴趣的小伙伴们可以参考本文
本文为大家分享了html5打开本地app应用的方法,具体内容如下
首先为了保证能够打开你的app,你必须要在androidmanifest.xml中配置的filter中data的属性表述。c8a388f9b2fa2891ea7078ec60da00d107b4fdd0136efc154b4b9d48cfcbbb9d androidmanifest.xml代码如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.taoge"
android:versioncode="2"
android:versionname="3.24.03" >
<uses-sdk
android:minsdkversion="8"
android:targetsdkversion="17" />
<application
android:allowbackup="true"
android:configchanges="orientation|screensize"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:logo="@drawable/logo"
android:shareduserid="android.uid.system"
android:theme="@android:style/theme.light.notitlebar" >
<activity
android:name="xttblog.welcomeactivity"
android:excludefromrecents="true"
android:screenorientation="portrait"
android:theme="@android:style/theme.light.notitlebar" >
<intent-filter>
<action android:name="android.intent.action.main" />
<category android:name="android.intent.category.launcher" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.view" />
<category android:name="android.intent.category.browsable" />
<category android:name="android.intent.category.default" />
<data android:pathprefix="/taoge/open"
android:scheme="xttblog" />
</intent-filter>
</activity>
<activity
android:name="xttblog.antrepairactivity"
android:label="@string/title_activity_ant_repair" >
</activity>
</application>
</manifest>
其次,你要在你的网页中访问xttblog://taoge/open。可以使用的元素有很多,如:script,iframe,img等。使用它们的src属性,访问xttblog://taoge/open。html5代码如下:
<!doctype html>
<html>
<script>
function openapp(){
document.getelementbyid('xttblog').innerhtml='<iframe src="xttblog://taoge/open"></iframe>';
}
</script>
<body>
<p style="display:none;" id="xttblog"></p>
<input type="button" value="打开app" onclick="openapp();">
</body>
</html>
以上就是html5打开本地app应用的示例代码的详细内容。
