h5页面唤醒app并跳转到指定页面
2018-03-27 12:01
465 查看
在manifest文件中最开始启动的activity中添加:
<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:host="host" android:pathPrefix="/pathPrefix" android:scheme="scheme" /> </intent-filter> //注意host,pathPrefix,scheme都是自己自定义的,只要与h5页面调用的一致即可,如下所示
<activity android:name=".activitys.MainActivity" android:label="@string/app_name" android:screenOrientation="portrait"> <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:host="host" android:pathPrefix="/pathPrefix" android:scheme="scheme" /> </intent-filter> </activity> 如果要跳转到指定的页面,在MainActivity的onCreate()中添加:
Intent intent = getIntent(); Uri uri = intent.getData(); if (uri != null) { String routeId = uri.getQueryParameter("pid"); Intent intent0 = new Intent(MainActivity.this, ZhidingActivity.class); startActivity(intent0); }
uri.getQueryParameter("pid");获取h5页面传递的参数,如果没有的话可以忽略<span style="font-size:18px;"><script>
注意一点,微信上对于app的唤醒有拦截,在浏览器中才可以起作用对于h5的代码如下:
function startAPP(){
window.location = "scheme://host/pathPrefix";
}
function downloadAPP(){
window.location = "apk下载地址";
}
</script>
<style type="text/css">
body{background:#D2D460;text-align:center;margin-top:10%}
div{width:100%;margin:0 auto;background:#fff;text-align:left;}
</style>
</head>
<body>
<?php
$var_name = $_GET["isappinstalled"];
if ($var_name=="1"){
echo '<img src=images/start.png alt=打开APP onclick=startAPP() ></img>';
}else if ($var_name=="0"){
echo '<img src=images/download.png alt=打开APP onclick=downloadAPP() ></img>';
}else{
echo '<img src=images/welcome.png alt=打开APP onclick=startAPP() ></img>';
}
?>
</body></span>
一定要注意:
window.location = "scheme://host/pathPrefix";scheme,host,pathPrefix一定要与android定义的一致
如果要传递参数的话:在后面拼接?pid=...即可实现原理最近,在使用QQ和微信等SDK来实现分享网页的时候,发现,SDK已经为页面跳转回应用提供了基本的数据支持。我们只需在应用里和被分享的网页进行简单的设置,即可实现此功能。那么我们先来看下网页跳转回应用的实现原理。就Android平台而言,URI主要分三个部分:scheme, authority and path。其中authority又分为host和port。格式如下:
scheme://host:port/path
举个实际的例子:
content://com.example.project:200/folder/subfolder/etc
\---------/ \---------------------------/ \---/ \--------------------------/
scheme host port path
\--------------------------------/
authority 现在大家应该知道data flag中那些属性的含义了吧,看下data flag
<data android:host="string"
android:mimeType="string"
android:path="string"
android:pathPattern="string"
android:pathPrefix="string"
android:port="string"
android:scheme="string" />
点击微信和QQ分享跳转到程序内部的原理与此一致。写在后面:由于微信在5.0.3以后就禁用了微信浏览器里打开别的app,所以上面的方法在微信里不能直接起作用。但是我们有补救方法,1,通过跳转应用宝,来判断是否安装应用,如果安装应用宝会直接打开2,引导用户在浏览器里打开当前网页,因为微信虽然禁止了android:scheme跳转,但是浏览器都是支持的。
相关文章推荐
- H5唤醒app并跳转到指定页面
- Android实现深度链接(APP外带动态参数唤醒APP,并跳转指定页面,APP不论在不在运行都可以)
- H5跳转到APP指定页面
- H5页面唤醒App及App之间跳转
- h5页面唤醒APP指定页面并传参
- JS和安卓互相调用以及Scheme协议完成外部链接跳转app指定页面
- h5页面唤起app(iOS和Android),没有安装则跳转下载页面
- 点击外部链接跳转App指定页面SingleTask模式
- h5判断移动设备是否安装了某app,有跳转,无则跳至下载页面
- 网页启动App&网页跳转到App指定的页面
- ios俩个APP之间跳转、传值,以及直接跳转到指定app页面 或者 app 评价页面 的方法
- 浏览器网页网址唤起微信app跳转到指定任意页面二维码识别方法ticket生成研究
- iOS 一个app跳转另一个app并实现通信(如A跳到B并打开B中指定页面)
- 微信6.66版本浏览器网页唤起微信app跳转到指定任意页面二维码识别方法ticket生成
- 关于h5界面无法用a标签在app内唤醒支付宝微信跳转
- H5页面唤醒app的方法
- ios 应用中直接跳转到指定app页面 或者 app 评价页面 的方法
- JS和安卓互相调用以及Scheme协议完成外部链接跳转app指定页面
- JS和安卓互相调用以及Scheme协议完成外部链接跳转app指定页面
- 奇酷360 手机中怎么跳转安全中心中指定包名App的权限管理页面