Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here I am sharing code that can load image in form of bitmap from and save that image on sdcard gallery in app name folder. You should follow these steps </p> <ol> <li>Download Image Bitmap first</li> </ol> <pre> <code> private Bitmap loadBitmap(String url) { try { InputStream in = new java.net.URL(url).openStream(); return BitmapFactory.decodeStream(in); } catch (Exception e) { e.printStackTrace(); } return null; } </code> </pre> <ol> <li>Please also provide following permission in your AndroidManifest.xml file.</li> </ol> <pre> <code> uses-permission android:name="android.permission.INTERNET" uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" </code> </pre> <ol> <li>Here is whole code that is written in Activty in which we want to perform this task.</li> </ol> <pre> <code> void saveMyImage(String appName, String imageUrl, String imageName) { Bitmap bmImg = loadBitmap(imageUrl); File filename; try { String path1 = android.os.Environment.getExternalStorageDirectory() .toString(); File file = new File(path1 + "/" + appName); if (!file.exists()) file.mkdirs(); filename = new File(file.getAbsolutePath() + "/" + imageName + ".jpg"); FileOutputStream out = new FileOutputStream(filename); bmImg.compress(Bitmap.CompressFormat.JPEG, 90, out); out.flush(); out.close(); ContentValues image = new ContentValues(); image.put(Images.Media.TITLE, appName); image.put(Images.Media.DISPLAY_NAME, imageName); image.put(Images.Media.DESCRIPTION, "App Image"); image.put(Images.Media.DATE_ADDED, System.currentTimeMillis()); image.put(Images.Media.MIME_TYPE, "image/jpg"); image.put(Images.Media.ORIENTATION, 0); File parent = filename.getParentFile(); image.put(Images.ImageColumns.BUCKET_ID, parent.toString() .toLowerCase().hashCode()); image.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, parent.getName() .toLowerCase()); image.put(Images.Media.SIZE, filename.length()); image.put(Images.Media.DATA, filename.getAbsolutePath()); Uri result = getContentResolver().insert( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, image); Toast.makeText(getApplicationContext(), "File is Saved in " + filename, Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); } } </code> </pre> <ol> <li>Hope that it can solve your whole problem.</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload