Android 图片保存到本地,更新相册,并且打开微信发送图片的时候,可以被识别
测了一下,大部分手机都可以适配,不适配的再找别的吧

    public static void saveImageToGallery(Bitmap mBitmap) {        if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {            return;        }        // 首先保存图片        File appDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsoluteFile();        if (!appDir.exists()) {            appDir.mkdir();        }        String fileName = System.currentTimeMillis() + ".jpg";        File file = new File(appDir, fileName);        try {            FileOutputStream fos = new FileOutputStream(file);            mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);            fos.flush();            fos.close();        } catch (FileNotFoundException e) {            e.printStackTrace();            return;        } catch (IOException e) {            e.printStackTrace();            return;        }        //把文件插入到系统图库 保存的路径为 Environment.DIRECTORY_DCIM   和 下方的  Uri.fromFile(file) 一起用 会造成 部分手机(华为P20 ,OPPO A83 ,美图手机等) 插入两张相同的图片,一张为当前时间 一张为 1970.01.01 时间的;        // Google Pixel 的手机 表示 没保存成功,保存之后 找不到,不作处理了,后期再单独优化。//        try {//            MediaStore.Images.Media.insertImage(getApplication().getContentResolver(), file.getAbsolutePath(), fileName, null);//        } catch (FileNotFoundException e) {//            e.printStackTrace();//        }        // 注释掉上方插入图库代码,  只去通知更新当前文件, 不影响 微信等正常读取图片        // 最后通知图库更新   Uri.parse("file://" + "") 更新之后,微信识别不出来,        // Uri.fromFile(file) 可以被微信识别出来//        getApplication().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + "")));        getApplication().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));    }

更多相关文章

  1. android下图片处理方法[转]
  2. android 循环播放图片实现
  3. 【Android开发经验】FaceBook推出的Android图片加载库-Fresco
  4. android 编译facebook/fresco图片库
  5. Android(安卓)MaskedImage
  6. [android UI]自定义各种UI,收集在此,以备后用!
  7. Android培训班(43)
  8. 《第一行代码Android》学习总结第八章 使用摄像头与相册
  9. android-TabHost标签控件的图片和文字不能同时显示解决方案

随机推荐

  1. android root实践
  2. Android之RecycleView实现指定范围的拖动
  3. 利用 Python 进行多 Sheet 表合并、多工
  4. Android知识点总结(十五) Android(安卓)MVP
  5. android BLE 4.0 setCharacteristicNotif
  6. Android系统横竖屏切换时候Activity的生
  7. Android(安卓)自定义ContentProvider和Co
  8. Android(安卓)GPS学习笔记—LMS初始化
  9. Android(安卓)代码中对不同国家支持的信
  10. android之Handler的使用,回到主线程更新UI