2015-09-18 198 views
1

這就是我的活動宣言深層鏈接ERR_UNKNOWN_URL_SCHEME

<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"> - 但我得到相同的錯誤。

UPDATE 我已經建議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
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()" />