模仿大众点评,通过微信扫一扫直接打开本地安装的大众点评,如果没安装就跳转到下载界面
下边是大众点评的跳转页面:
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<script>
var hipCityId = 0;
if(hipCityId > 0){
var _hip = [
['_setPageId', 2010003],
['_setCityId', 0]
];
}
</script>
</head>
<body>
<script type="text/javascript" src="http://m1.s2.dpfile.com/hls/hippo2.min.376e5aee201f773050a4842e4fd097c4.js"></script>
<script>
var isAndroid = false;
var iPhone = false;
var iPad = false;
var userAgent = navigator.userAgent;
var downloadUrl = "";
if (userAgent.match("Android") || userAgent.match("android")){
isAndroid = true;
downloadUrl = '';
}else if (userAgent.match("iPhone")){
iPhone = true;
downloadUrl = 'http://itunes.apple.com/cn/app/id351091731?utm_source=__epa';
}else if (userAgent.match("iPad")){
iPad = true;
downloadUrl = '';
}
var redirect_url = "";
if(isAndroid || iPhone || iPad){
var startTime = Date.now();
div = document.createElement('div');
div.style.visibility = 'hidden';
div.innerHTML = '<iframe id="schema" src="' + 'dianping://home?utm_=w_tuanpc_home' + '" scrolling="no" width="1" height="1"></iframe>';
document.body.appendChild(div);
var delta = Date.now() - startTime;
if(delta < 200){
startTime = Date.now();
document.getElementById("schema").src="";
delta = Date.now() - startTime;
if(delta < 200){
if(downloadUrl!==null && downloadUrl!==''){
redirect_url = downloadUrl;
_hip.push(['mv', {module:'synthesislink_3224',action:'click'}]);
}else{
}
}
}
}else{
redirect_url = downloadUrl;
}
if(redirect_url){
setTimeout(function(){
window.location = redirect_url;
}, 500);
}
</script>
<div class="title">大众点评客户端</div>
<div class="photo">
<img src="http://m1.s1.dpfile.com/sc/download/background.png">
</div>
<div class="link">
<a class="download-banner" onclick="downloadFunc()" href="javascript:void(0)">下载客户端</a>
<a class="go-on" onclick="window.history.go(-1)" href="javascript:void(0)" >继续访问</a>
</div>
<style>
body {
background-color: #eeeeee;
margin: 0;
text-align: center;
}
img {
width: 130px;
height: 223px;
}
.title {
color: #333333;
margin-top: 30px;
margin-bottom: 30px;
font-size: 24px;
line-height: 24px;
text-align: center;
}
.photo {
text-align: center;
}
.link {
font-size: 16px;
margin-top: 20px;
}
.download-banner,.go-on {
width: 120px;
border-radius: 4px;
height: 40px;
display: inline-block;
line-height: 40px;
text-decoration: none;
}
.download-banner {
background-color: #ff6633;
color: white;
}
.go-on {
background-color: #ffffff;
margin-left: 8px;
color: #666666;
text-decoration: none;
}
</style>
<script>
function downloadFunc(){
var dlLink = "http://m.api.dianping.com/downloadlink?redirect=3259";
var ua = navigator.userAgent;
if(ua.indexOf("Android") > 0){
var androidLink = 'http://i2.dpfile.com/download/dianping-qr_6.9.6.apk?utm_source=__epa';
if(androidLink!=null && androidLink!="" && androidLink.indexOf(".apk")>0){
dlLink = androidLink;
}
}
window.location = dlLink;
}
</script>
</body>
</html>
下面是大众点评android版本破解的配置文件关键部分:
<data android:host=”forward” android:scheme=”dianping”/>
<activity android:label="@string/app_name" android:name="com.dianping.loader.ForwardActivity" android:screenOrientation="nosensor" android:theme="@android:style/Theme.Translucent.NoTitleBar">
<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="forward" android:scheme="dianping"/>
</intent-filter>
</activity>
<activity-alias android:exported="true" android:label="@string/app_name" android:name="com.dianping.v1.ForwardActivity" android:targetActivity="com.dianping.loader.ForwardActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity-alias>
<activity android:configChanges="keyboardHidden|orientation" android:label="@string/app_name" android:name="com.dianping.main.guide.SplashScreenActivity" android:screenOrientation="nosensor" android:theme="@style/Theme.DianpingNoTitle.SplashBackground">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
综上,其实通过网页启动Activity是通过Activity所配置的隐式Intent方式(配置在AndroidManifest中)
精简以上代码后,如下:
1.在Manifest文件中给TestActivity配置一个隐式Intent
<activity android:name=".activity.TestActivity">
<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="test"
android:scheme="testapp" />
</intent-filter>
</activity>
2.在网页中点击链接<a href=”testapp://test”>Start TestActivity</a>就会启动TestActivity了
注:category是类别匹对,data是数据匹对,data属性是一个URI, URI中包含scheme, host, post和path, 典型的URI为:scheme://host:port/path,现在明白链接中为什么要<a href=”testapp://test”>这样写了吧
3.如果传递参数
Html中:<a href=”testapp://test?id=100101&title=HelloAndroid”>StartTestActivity</a>
Uri uri = getIntent().getData();
Strinng id = uri.getQueryParameter("id");
Strinng title = uri.getQueryParameter("title");
这样就可以实现参数的传递了
参考资料:http://my.oschina.net/liucundong/blog/354029?p=5#comments