这是我的活动声明
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<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="example"
android:path="/"
android:scheme="ray1984" />
</intent-filter>
</activity>
在genymotion模拟器中,我打开我的简单html
<html>
<body>
<a href="intent://example/#Intent;scheme=ray1984;package=com.github.ray1984.deeplink;end">Deep link</a>
</body>
在链接上点击我希望申请开放,但我收到错误网:: ERR_UNKNOWN_URL_SCHEME
此外,我尝试了简单的深层链接 - <a href="ray1984://example">
- 但我得到了同样的错误。
更新 我已经通过建议改变了HTML:
<html>
<head>
<script type="text/javascript">
var custom = "ray1984://example";
var alt = "http://google.com/";
var g_intent = "intent://example/#Intent;scheme=ray1984;package=com.github.ray1984.deplink;end";
var timer;
var heartbeat;
var iframe_timer;
function clearTimers() {
clearTimeout(timer);
clearTimeout(heartbeat);
clearTimeout(iframe_timer);
}
function intervalHeartbeat() {
if (document.webkitHidden || document.hidden) {
clearTimers();
}
}
function tryIframeApproach() {
var iframe = document.createElement("iframe");
iframe.style.border = "none";
iframe.style.width = "1px";
iframe.style.height = "1px";
iframe.onload = function () {
document.location = alt;
};
iframe.src = custom;
document.body.appendChild(iframe);
}
function tryWebkitApproach() {
document.location = custom;
timer = setTimeout(function () {
document.location = alt;
}, 2500);
}
function useIntent() {
document.location = g_intent;
}
function launch_app_or_alt_url(el) {
heartbeat = setInterval(intervalHeartbeat, 200);
if (navigator.userAgent.match(/Chrome/)) {
useIntent();
} else if (navigator.userAgent.match(/Firefox/)) {
tryWebkitApproach();
iframe_timer = setTimeout(function () {
tryIframeApproach();
}, 1500);
} else {
tryIframeApproach();
}
}
$(".source_url").click(function (event) {
launch_app_or_alt_url($(this));
event.preventDefault();
});
</script>
</head>
<body>
<button class="source_url">Click me</button>
</body>
</html>
但是按钮点击没有任何反应
答案 0 :(得分:0)
Do these changes
change function launch_app_or_alt_url(el) to function launch_app_or_alt_url()
and remove this
$(".source_url").click(function (event) {
launch_app_or_alt_url($(this));
event.preventDefault();
});
and change this <button class="source_url">Click me</button> to
<input type="button" value="click" onClick="launch_app_or_alt_url()" />