android保存图片到图库
16lz
2021-01-23
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)));}
更多相关文章
- Android文件图片上传的详细讲解(三)---模式回调类
- android XML文件序列化
- Android Studio(十二):打包多个发布渠道的apk文件
- [置顶] Android——4.2.2 文件系统目录分析
- Linux下 解包/打包 Android 映像文件 system.img, boot.img, ram
- AndroidManifest.xml 配置文件
- Android Studio R.java文件在哪