首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >深链ERR_UNKNOWN_URL_SCHEME

深链ERR_UNKNOWN_URL_SCHEME
EN

Stack Overflow用户
提问于 2015-09-18 19:00:43
回答 1查看 1.6K关注 0票数 1

那是我的活动声明

代码语言:javascript
复制
<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。

代码语言:javascript
复制
<html>
<body>
    <a href="intent://example/#Intent;scheme=ray1984;package=com.github.ray1984.deeplink;end">Deep link</a>
</body>

单击链接,我希望应用程序打开,但是我得到了错误的net::ERR_UNKNOWN_URL_SCHEME

另外,我尝试了简单的深度链接-- <a href="ray1984://example"> --但是我也得到了同样的错误。

更新我通过建议更改了:

代码语言:javascript
复制
<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>

但是按一下按钮,什么都不会发生

EN

回答 1

Stack Overflow用户

发布于 2015-09-19 09:50:09

代码语言:javascript
复制
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()" />
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32659249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档