publicstaticvoidsaveImageToGallery(Contextcontext,Bitmapbmp){//首先保存图片FileappDir=newFile(Environment.getExternalStorageDirectory(),"Boohee");if(!appDir.exists()){appDir.mkdir();}StringfileName=System.currentTimeMillis()+".jpg";Filefile=newFile(appDir,fileName);try{FileOutputStreamfos=newFileOutputStream(file);bmp.compress(CompressFormat.JPEG,100,fos);fos.flush();fos.close();}catch(FileNotFoundExceptione){e.printStackTrace();}catch(IOExceptione){e.printStackTrace();}//其次把文件插入到系统图库try{MediaStore.Images.Media.insertImage(context.getContentResolver(),file.getAbsolutePath(),fileName,null);}catch(FileNotFoundExceptione){e.printStackTrace();}//最后通知图库更新context.sendBroadcast(newIntent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.parse("file://"+path)));}


更多相关文章

  1. Android文件图片上传的详细讲解(三)---模式回调类
  2. android XML文件序列化
  3. Android Studio(十二):打包多个发布渠道的apk文件
  4. [置顶] Android——4.2.2 文件系统目录分析
  5. Linux下 解包/打包 Android 映像文件 system.img, boot.img, ram
  6. AndroidManifest.xml 配置文件
  7. Android Studio R.java文件在哪

随机推荐

  1. Android开发中如何监听指定URL地址的标签
  2. Android的致命问题——性能优化
  3. 【Android】画廊式的图片浏览器,使用Horiz
  4. Android(安卓)4.2 新特性体验
  5. java版 android遥控电脑关机
  6. Android开发之天气预报(四)UI界面实现
  7. Android笔面试
  8. Android参考书籍
  9. 聊聊 Android(安卓)中的三大框架
  10. Android中使用socket使底层和framework通