这个方式也兼容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:https://gist.github.com/FokkeZB/6635236 我使用的是这篇文章中js的实现方式, 这篇文章也有后端php的实现方式。

更多相关文章

  1. GitHub 标星 2.5K+!教你通过玩游戏的方式学习 VIM!
  2. 【Android】Async异步任务之添加进度条
  3. Retrofit2的使用
  4. http上传文件到网络核心代码
  5. 一起学android之SimpleAdapter使用(13)
  6. Android如何通过scheme跳转界面
  7. Ubuntu Android(安卓)Studio快捷方式创建
  8. Android学习笔记:Activity-Spinner
  9. 几个Android常见wraning警告处理方法

随机推荐

  1. 判断客户端类型
  2. 【Android(安卓)Demo】Android中取得手机
  3. Android中JNI实现
  4. android map
  5. Android(安卓)LayoutInflater.inflate(R.
  6. android 通过广播获取指定联系人短信内容
  7. Android(安卓)MTK Launcher3 替换桌面图
  8. 2013.12.04 (4)——— android SlidingMenu
  9. Android开源项目
  10. 解决Flutter 编译异常path_provider