zoukankan      html  css  js  c++  java
  • 解决webview.getFavicon()返回值总是为空的问题

    在webview中,我们需要获取网站的favicon.ico图标,但是默认状态下,WebChromeClient中的onReceivedIcon方法获取到的icon总是为null;

    webview.getFavicon();获得到的还是null,这个就奇怪了,于是

    经过一番google,发现老外也遇到了这个问题.

    =======================================================

    http://stackoverflow.com/questions/3462582/display-the-android-webviews-favicon


    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() method has a favicon parameter that is always null.

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

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

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


    其中有个回答解决了这个问题.

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

    Try adding the following line to onCreate():
    WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());

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

  • 相关阅读:
    查詢一個表中的所有字段,一个表的结构
    二月份工作總結
    导出excel [原创]
    一个it老总对于新人的一点建议
    命名空间的别名
    mssql 格式化时间 [转]
    开发人员一定要加入收藏夹的网站
    sql 导出/入Excel
    hibernate中hbm文件中inverse功能
    详细展示Asp.net页面的生命周期[转]
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/5466533.html
Copyright © 2011-2022 走看看