android保存图片到图库
2015-11-26 14:36
441 查看
public static void saveImageToGallery(Context context, Bitmap bmp) { // 首先保存图片 File appDir = new File(Environment.getExternalStorageDirectory(), "Boohee"); if (!appDir.exists()) { appDir.mkdir(); } String fileName = System.currentTimeMillis() + ".jpg"; File file = new File(appDir, fileName); try { FileOutputStream fos = new FileOutputStream(file); bmp.compress(CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // 其次把文件插入到系统图库 try { MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), fileName, null); } catch (FileNotFoundException e) { e.printStackTrace(); } // 最后通知图库更新 context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + path)));}
相关文章推荐
- android studio下Material Design库的使用
- Android4.0的Alertdialog对话框,设置点击其他位置不消失
- Android性能优化之避免内存泄漏的建议
- Android 通过监听收信箱获取短信,Cursor对象字段的详细信息
- android 多分辨率机型适配文件夹命名规则
- [Android]startActivityForResult启动singleTask的Activity,则onActivitResult()立即回调且resultCode为RESULT_CANCEL
- Android第三方资源使用之ImageCache
- Android第三方资源使用之ImageCache
- Android 四大组件之Service
- Android M 优化电池性能的 Doze 模式工作原理是怎样的?
- android webview js alert对话框 不能弹出 解决办法
- Android之调用本地摄像头
- android权限大全
- Android使用Unicode码对中文进行字母索引的2种方法
- Android Service的生命周期
- Android系统主题样式属性
- android adb bundle下载
- 关于安卓学习的方法(简单补充)
- Android应用开发SharedPreferences存储数据的使用方法
- ANDROID开发之SQLite详解