1.需求:
需要将远程传回的文件保存到本地,并实时更新图库
2.代码实现:
private void saveScreenshotPictures(Bitmap mScreenshotbitmap){
fileName = "/storage/emulated/0/smarttv/screenshots/"+
generateFileName()+".png";
LogUtils.i("mScreenshotbitmap = "+mScreenshotbitmap);
if(mScreenshotbitmap == null){
return;
}
File filePic ;
try{
LogUtils.i("fileName = "+fileName);
filePic = new File(fileName);
if(!isDirExist()){
mkStoragedir();
filePic.createNewFile();
} else {
filePic.createNewFile();
}
FileOutputStream fos = new FileOutputStream(filePic);
mScreenshotbitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush(); fos.close();
//begin added by sineng.li for XR 7232788 TCT_SmartTV update pictures database after saving action on 20181220
updateFileFromDatabase(getContext(),filePic);
//end added by sineng.li for XR 7232788 TCT_SmartTV update pictures database after saving action on 20181220
}catch (IOException e){
e.printStackTrace();
}
}
@NonNull
private String generateFileName(){
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat(PICTURE_NAME_FORMAT);
String dateString = formatter.format(currentTime);
return "TV_Screenshot_"+dateString;
}
有很多信息涉及到公司的,就改了一些,你们自己调试一下看能不能运行。