在android浏览器中如果安装了app,则打开app,如果没有则跳转到应用市场下载。...

这个方式也兼容ios。

先看html

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>App Redirection</title>
</head>
<body>


<script>
var IS_IPAD = navigator.userAgent.match(/iPad/i) != null,
IS_IPHONE = !IS_IPAD && ((navigator.userAgent.match(/iPhone/i) != null) || (navigator.userAgent.match(/iPod/i) != null)),
IS_IOS = IS_IPAD || IS_IPHONE,
IS_ANDROID = !IS_IOS && navigator.userAgent.match(/android/i) != null,
IS_MOBILE = IS_IOS || IS_ANDROID;

function open() {

// If it's not an universal app, use IS_IPAD or IS_IPHONE
if (IS_IOS) {
window.location = "myapp://view?id=123";

setTimeout(function() {

// If the user is still here, open the App Store
if (!document.webkitHidden) {

// Replace the Apple ID following '/id'
window.location = 'http://itunes.apple.com/app/id1234567';
}
}, 25);

} else if (IS_ANDROID) {

// Instead of using the actual URL scheme, use 'intent://' for better UX
window.location = 'intent://view?xxxx=123#Intent;package=com.example.myapp;scheme=vip;launchFlags=268435456;end;';

}
}

open();
</script>
</body>
</html>


android app中androidminifest.xml的activity的设置,具体看MyActivity

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="19"/>
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:hardwareAccelerated="true">
<activity android:name=".MyActivity">
<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.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="vip" android:path="/view" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>


在activity获取传入的参数xxxx的值,需要解析Uri方式来获取

package com.example.myapp;


import org.apache.http.protocol.UriPatternMatcher;

import java.net.URI;
import java.net.URISyntaxException;

public class MyActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String s = getIntent().toURI();
Uri parse = Uri.parse(s);
String xxxx = parse.getQueryParameter("xxxx");

Log.d("MyActivity", xxxx);
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.d("MyActivity", "xx" + getIntent().toURI());
}
}



Reference:[url]https://gist.github.com/FokkeZB/6635236[/url] 我使用的是这篇文章中js的实现方式, 这篇文章也有后端php的实现方式。
要使用uni-app内置的uni.navigateTo方法跳转到系统浏览器打开知乎网页,可以按照以下步骤进行操作: 1. 在需要跳转的页面中,使用uni.navigateTo方法跳转到一个中间页面(例如名为"externalLink"的页面)。 ```javascript uni.navigateTo({ url: '/pages/externalLink' }); ``` 2. 在"externalLink"页面的onLoad生命周期函数中,使用uni.getSystemInfo方法获取当前系统信息,并根据系统信息判断要打开的链接。 ```javascript onLoad() { uni.getSystemInfo({ success: (res) => { const platform = res.platform.toLowerCase(); let url = ''; if (platform === 'android') { url = 'intent://www.zhihu.com/#Intent;scheme=https;package=com.android.chrome;end'; } else if (platform === 'ios') { url = 'https://www.zhihu.com/'; } else { // 其他平台处理 } this.openExternalLink(url); } }); }, methods: { openExternalLink(url) { uni.redirectTo({ url: `/pages/webview?url=${encodeURIComponent(url)}` }); } } ``` 3. 在"externalLink"页面的methods中,定义openExternalLink方法,并通过uni.redirectTo方法跳转到一个webview页面,并将要打开的链接作为参数传递给webview页面。 ```javascript openExternalLink(url) { uni.redirectTo({ url: `/pages/webview?url=${encodeURIComponent(url)}` }); } ``` 4. 创建一个webview页面(例如名为"webview"的页面),用于展示外部链接。 ```html <template> <view class="container"> <web-view :src="url"></web-view> </view> </template> <script> export default { data() { return { url: '' }; }, onLoad(options) { this.url = decodeURIComponent(options.url); } }; </script> ``` 在这个示例中,通过判断当前系统平台(Android或iOS),选择不同的网页链接进行跳转Android平台使用intent协议打开Chrome浏览器,iOS平台直接使用https协议打开知乎网页。 请注意,在跳转到webview页面时,需要将要打开的链接进行encodeURIComponent编码,以避免URL中的特殊字符引起的问题。 以上是使用uni-app内置的方法跳转到系统浏览器打开知乎网页的示例代码。您可以根据实际需求进行适当调整和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值