显示了Android的WebView的图标 [英] Display the Android WebView's favicon

查看:885
本文介绍了显示了Android的WebView的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想展示我通过android.webkit.WebView访问该网站的图标。我试过两种方式来获得它:

I'd like to display the favicon of the website I am accessing via the android.webkit.WebView. I've tried two ways to get it:

1) WebViewClient.onPageStarted()方法有一个图标参数总是空。

1) WebViewClient.onPageStarted() method has a favicon parameter that is always null.

2) WebChromeClient.onReceivedIcon()方法不会被调用。

2) WebChromeClient.onReceivedIcon() method is never called.

3)名为 WebView.getFavicon() onPageStarted() onPageFinished( )但它总是返回null。

3) Called WebView.getFavicon() in onPageStarted() and onPageFinished() but it always returns null.

我一直没能找到一个例子网上展示了如何访问图标。任何提示将大大AP preciated。

I haven't been able to find an example online that shows how to access the favicon. Any hints would be greatly appreciated.

推荐答案

有关web视图图标的方法和听众的工作,你需要先手动打开WebIconDatabase。你通常会在你活动的的onCreate()办法做到这一点。

For the WebView icon methods and listeners to work, you need to first open the WebIconDatabase manually. You would typically do this in the onCreate() method of your Activity.

尝试添加以下行的onCreate()

WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());

一旦你做到了这一点,你应该开始让 onReceivedIcon()回调,本次活动的任何web视图,而 getFavicon()方法也开始返回一个有效的对象,而不是空时的图标是可用的。

Once you've done this, you should start getting onReceivedIcon() callbacks for any WebView in this Activity, and the getFavicon() method should also start returning a valid object rather than null whenever icons are available.

这篇关于显示了Android的WebView的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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