How to get high resolution website logo (favicon) for a given URL

前端 未结 5 1154
情深已故
情深已故 2020-12-13 14:29

I\'m developing a web browser on Android and want to show the URL logo for the most visited sites like in Chrome (4 X 2). But the problem is that most favicons (eg: http://w

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 14:39

    Here is a new and genuine solution which will always give you the best results-

    1. Webchromeclient gives a callback of onReceivedTouchIconUrl method for all the websites just hold the url from here.
    2. Next step is to convert this url to bitmap which can be done like this-

      try {
          URL url = new URL(touchiconUrl);
          HttpURLConnection connection =
                  (HttpURLConnection)url.openConnection();
          connection.setDoInput(true);
          connection.connect();
          InputStream input = connection.getInputStream();
          Bitmap myBitmap = BitmapFactory.decodeStream(input);
          return myBitmap;
      } catch (IOException e) {
          e.printStackTrace();
          return null;
      }
      
    3. Next step is to send this bitmap for the shortcut.

    Note: Remember to create bitmap on background thread like asynctask.

提交回复
热议问题