简体   繁体   English

如何在android webview app中打开特定链接?

[英]How to open specific link in android webview app?

I have integrated a website in an android app using WebView. 我使用WebView在Android应用程序中集成了一个网站。

webtcet.loadUrl("http://www.myaddaa.in/");
 webtcet.setWebViewClient(new MyWebviewClient());

private class MyWebviewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            view.loadUrl(url);
            return true;

        }
}

But when i try to open ads link in android app(running in my phone it has google play services) it shows could not be loaded. 但是,当我尝试在Android应用程序中打开广告链接(在我的手机中运行它有谷歌播放服务)它显示无法加载。

Webview包含沃达丰广告 点击下载图标后

So how would i open the link directly to playstore and not in webview if it is ads? 那么,如果它是广告,我将如何直接打开链接到Playstore而不是webview? Thank in advance 预先感谢

  1. I don'k think it's a good idea to open market directly inside the webview. 我认为直接在webview中打开市场是个好主意。 The best way is to pass the intent to play store like this 最好的方法是将意图传递给这样的商店

     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+YOU_APP_ID))); 
  2. If you really need this behaviour for some reason, you have to intercept all market:// links and load them as usual browser links 如果您出于某种原因确实需要此行为,则必须截取所有market://链接并将其作为常用浏览器链接加载

    webView.setWebViewClient(new WebViewClient() { webView.setWebViewClient(new WebViewClient(){

      @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (Uri.parse(url).getScheme().equals("market")) { [parse the link to get app id from url] webview.loadUrl(https://play.google.com/store/apps/details?id=[YOU_APP_ID]); } }); 

so just intercept this links inside your shouldOverrideUrlLoading 所以只需截取你的shouldOverrideUrlLoading中的这个链接

webView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (Uri.parse(url).getScheme().equals("market")) {
            try {
               startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                return true;
            } catch (ActivityNotFoundException e) {
                // open link in browser as described above
            }

        }
        return false;
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM