If you want to convert the base64 string to an image file (e.g. .png , etc.) and save it in some folder, you can use this code:
byte[] btDataFile = Base64.decode(base64Image, Base64.DEFAULT); String fileName = YOUR_FILE_NAME + ".png"; try { File folder = new File(context.getExternalFilesDir("") + /PathToFile); if(!folder.exists()){ folder.mkdirs(); } File myFile = new File(folder.getAbsolutePath(), fileName); myFile.createNewFile(); FileOutputStream osf = new FileOutputStream(myFile); osf.write(btDataFile); osf.flush(); osf.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
And make sure that you provide the following required permissions in the manifest file:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
anivaler
source share