2011-12-26 41 views
2

目前我有一個Android應用程序,基本上是一個Web視圖加載網頁。在網頁上,我tryed鏈接到市場上像這樣...如何從Android WebView鏈接到Android應用程序

https://market.android.com/details?id=com.google.earth 

http://market.android.com/details?id=com.google.earth 

market://details?id=com.google.earth 

第一個結果只是打開了一個白色的屏幕(這可能加載,但它一直是他們的一分多鐘) 。

第二個結果表明該頁面已被移動並顯示一個鏈接。如果你點擊第一個鏈接,它會做第一個鏈接。

第三個結果表示頁面可能暫時關閉。 (它的治療就像它的網上鍊接,而不是手機本身)

這裏是鏈接的樣子......

echo "<a href='https://market.android.com/details?id=com.google.earth' data-role='button'>Upgrade Now</a>"; 

記住網頁我加載使用JQuery Mobile和我m迴應與PHP的鏈接。

如何在網頁的webview中打開指向Android Market的鏈接?

+0

http://stackoverflow.com/questions/3239478/how-to-link-to-android- market-app – ethrbunny 2011-12-26 14:31:58

+0

這些都不適合我... – Joe 2011-12-26 15:00:09

+0

我會嘗試jQuery以外的鏈接,看看會發生什麼。 – ethrbunny 2011-12-26 15:13:21

回答

0

在我的情況,我得到了相同的空白/移動暫時麻煩描述。我想使用shouldOverrideUrlLoading,以便本機瀏覽器不會在從我的頁面到Google的oauth2流中使用並返回到我的頁面。我的android應用程序正在使用自簽名證書與localhost/tomcat通話。原來我需要調用繼續,因爲證書不匹配:

webView.setWebViewClient(new WebViewClient(){ 
    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     Log.i("DevAgentSocialMain", "URL: " + url); 
     view.loadUrl(url); 
     return true; 
    } 

    @Override 
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 
     Log.i("DevAgentSocialMain", "onReceivedError: " + errorCode + " " + description + " url: " + failingUrl); 
     super.onReceivedError(view, errorCode, description, failingUrl); 
    } 

    @Override 
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { 
     Log.i("DevAgentSocialMain", "onReceivedSslError: " + error.getPrimaryError()); 
     //super.onReceivedSslError(view, handler, error); 
     handler.proceed(); 
    } 
}); 
0

這可以幫助你

public boolean shouldOverrideUrlLoading(WebView view, String url) 
{ 
    if (url.startsWith("market://")||url.startsWith("vnd:youtube")||url.startsWith("tel:")||url.startsWith("mailto:")||url.startsWith("intent://")) 
    { 
     Intent intent = new Intent(Intent.ACTION_VIEW); 
     intent.setData(Uri.parse(url)); 
     startActivity(intent); 
     return true; 
    } 
    else{ 
     view.loadUrl(url); 
     return true; 
     } 
} 

} 
+2

請解釋這段代碼如何回答這個問題。 – rfornal 2015-01-09 15:41:30

相關問題