title: How to save base64 jpg file in android?
body: <p>I get base64 String as is in link below, with jpeg image. It works for many images, but sometimes not. I tried <em>Base64.DEFAULT</em>, <em>NO_WRAP</em> and <em>NO_CLOSE</em> but nothing works everytime. It works on ios or on pc version.</p>
  
  <pre><code>byte[] imageAsBytes = Base64.decode(base64ImageData.getBytes(), Base64.DEFAULT);
  try {
      imageView.setImageBitmap(BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length));
  }catch(OutOfMemoryError e){
  }
  </code></pre>
  
  <p>another attempt which also doesnt work:</p>
  
  <pre><code>fos = new FileOutputStream(file);
  byte[] decodedString = android.util.Base64.decode(base64ImageData, Base64.DEFAULT);
  fos.write(decodedString);
  //line below helps for some images
  //fos.write(System.lineSeparator().getBytes());
  fos.flush();
  fos.close();
  
  Uri uri = Uri.fromFile(f);
  imageView.setImageURI(uri);
  </code></pre>
  
  <p>in android file explorer, saved file can be opened on some phones or also in windows os.</p>
  
  <p>image base64 data example <a href="http://justpaste.it/pquv" rel="nofollow">http://justpaste.it/pquv</a></p>
  
  <p>I dont know where can be problem</p>