Android開発:SDカードに画像を保存

2360 ワード

 1 byte[] bytes = decodeImagStr(imgString);//  base64       

 2         if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){//  sd    

 3             String pathDir= Environment.getExternalStorageDirectory()+ ConstantsForFile.TMP_FILE_DIRECTORY;//        

 4             String picName =new Date().getTime()+".jpg";

 5             File dirFile = new File(pathDir);

 6             if(!dirFile.exists())dirFile.mkdirs();//      ,   ,mkDirs                

 7             File picFile = new File(pathDir,picName);//      

 8             FileOutputStream fileOutputStream = new FileOutputStream(picFile);//       

 9             fileOutputStream.write(bytes);//    

10             fileOutputStream.flush();

11             fileOutputStream.close();

12             return picFile.getPath();//      

13         }