从网络视图打开应用程序链接 [英] opening app links from a webview

查看:101
本文介绍了从网络视图打开应用程序链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个android应用程序,有一个带有webView的活动,它的作用类似于浏览器(它打开了我提供的一些链接).每当我浏览webView时,如果有链接导致Play商店下载我的webView无法响应的应用程序,则会显示网页不可用".它无法发送意图打开Play商店或类似Google chrome的意图.我该怎么办?

I have an android app, there is an activity with a webView, it acts like a browser (it open some links I provided). Whenever I browse through my webView if there is a link that leads to play store to download an app my webView can't respond, it says 'webpage not available'. It can't send an intent to open play store or something like google chrome. How can I do it?

推荐答案

这适用于我并打开play store应用(如果已安装),否则显示playstore 同一webView中的链接.

This works for me and opens play store app if it is installed and else shows playstore link within the same webView.

webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (Uri.parse(url).getScheme().equals("market")) {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            Activity host = (Activity) view.getContext();
            host.startActivity(intent);
            return true;
        } catch (ActivityNotFoundException e) {
            Uri uri = Uri.parse(url);
            view.loadUrl("http://play.google.com/store/apps/" + uri.getHost() + "?" + uri.getQuery());
            return false;
        }

    }
    return false;
}
});

这篇关于从网络视图打开应用程序链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆