android代码获取网站图标
来源:互联网 发布:武则天 知乎 编辑:程序博客网 时间:2024/06/15 12:36
网站上的图标的获取,如百度的图标 的获取是在网站后面添加 /favicon.ico,如 http://www.baidu.com/favicon.ico 。
在android中获取网络上的图片并存储到本地,或者置于ImageView组件中.以下为获取URL上的图标并设置到ImageView的工具方法:
public static void getBitmapFromURL(final String url, final ImageView imageView, final Handler handler){ new Thread(new Runnable() { @Override public void run() { try { URL httpURL = new URL(url); HttpURLConnection conn = (HttpURLConnection) httpURL.openConnection(); conn.setReadTimeout(5000); conn.setRequestMethod("GET"); conn.setDoInput(true); InputStream in = conn.getInputStream(); // 获取输入流 FileOutputStream out = null; // 输出流 File file = null; // 从URL下载的文件 String fileName = url.replace("/", "").replace(":", "").replace("&", ""); // 用URL作为文件名,将其中的特殊字符去除 // 判断 SD卡是否存在 if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { File dir= Environment.getExternalStorageDirectory(); // 获取文件夹路径 file = new File(dir, fileName); // 获取到文件 out = new FileOutputStream(file); // 将文件写到本地存储 } byte[] b = new byte[1024]; // 设置缓冲区大小 int length; if(out != null) { while((length = in.read(b)) != -1) { out.write(b, 0, length); // 写入本地存储卡中 } } final Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); // 获取文件所在的位置 handler.post(new Runnable() { @Override public void run() { imageView.setImageBitmap(bitmap); } }); file.delete(); // 置于ImageView组件后,将SD卡上的图标文件删除 in.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } } }).start(); }
0 0
- android代码获取网站图标
- 获取网站图标
- Android icon图标网站
- 获取网站title的图标
- 网站地址栏的图标代码
- 网站收藏夹图标 添加代码
- 网站地址栏的图标代码
- 获取网站缩略图代码
- 创建网站快捷图标只需两行代码
- Android获取快捷方式图标信息
- 获取任意网站的图标,标题栏logo,网站logo
- 网站分享到代码获取
- android节点网站代码
- android代码网站
- 图标网站
- 图标网站
- 网站图标
- 图标网站
- 使用 WebStorm IDE 调试 Pomelo 应用程序
- 韵与度
- ORACLE日期时间函数大全
- 【图片裁剪】移动端一些处理措施
- activiti数据库表结构剖析
- android代码获取网站图标
- test3.10
- Oracle数据库的分页使用
- 移除父控件的所有子控件
- Java中的StringUtils类
- Spring AOP + AspectJ annotation example
- json格式化工具
- VB截取中英文混合字符串中若干半角单位长字串的函数
- flask环境