zoukankan      html  css  js  c++  java
  • Android图片下载到本地,系统图库不显示

    可能大家都知道我们下载图片到Android手机的时候,然后调用系统图库打开图片,提示“找不到指定项”。

    那是因为我们插入的图片还没有更新的缘故,所以只要将图片插入系统图库,之后发条广播就ok了。

    /**
         * 图片插入到系统相册,解决系统图库不能打开图片的问题
         */
        public static void insertImageToSystemGallery(Context context, String filePath, Bitmap bitmap){
            MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, "", "");
            Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            Uri uri = Uri.fromFile(new File(filePath));
            intent.setData(uri);
            context.sendBroadcast(intent);
        }
    

    附上获取图片路径的方法:

    //获取图片的绝对路径
    private  String getFilePathByContentResolver(Context context, Uri uri) {
    		if (null == uri) {
    			return null;
    		}
            Cursor c = context.getContentResolver().query(uri, null, null, null, null);
            String filePath  = null;
            if (null == c) {
                throw new IllegalArgumentException(
                        "Query on " + uri + " returns null result.");
            }
            try {
                if ((c.getCount() != 1) || !c.moveToFirst()) {
                } else {
                	filePath = c.getString(
                			c.getColumnIndexOrThrow(MediaColumns.DATA));
                }
            } finally {
                c.close();
            }
            return filePath;
        }
    

      

  • 相关阅读:
    vue-router过渡动画
    vue-router重定向
    vue-router url传值
    vue-router多个组件模板放入同一个页面中
    vue-router参数
    vue-router子路由
    vue-router入门
    easyui中parser的简单用法
    webpost中常用的ContentType
    ASP.NET MVC 表单提交多层子级实体集合数据到控制器中
  • 原文地址:https://www.cnblogs.com/hacjy/p/6023552.html
Copyright © 2011-2022 走看看