install android studio

Store image in gallery in Android Studio

Save Image :

The image can be saved in Mobile’s Gallery from Android app. There are many features are providing by the Android to work with user’s data . For saving the images , there is need to take permissions from the user manually or automatically to access the SD card of the mobile to insert or to take the data from the device

Here are some code to implement this generic problem in Android Studio .Do step by step :

1. Permissions:

uses-permission:android name="android.permission.WRITE_EXTERNAL_STORAGE"/>

2. SaveActivity.java:


OutputStream output; 
filepath = Environment.getExternalStorageDirectory();  File dir = new File(filepath.getAbsolutePath() + "/save/");
        dir.mkdirs(); 

BitmapDrawable drawable = (BitmapDrawable) principal.getDrawable(); Bitmap bitmap1 = drawable.getBitmap(); // Create a name for the saved image File file = new File(dir, "Wallpaper.jpg" ); try {

            output = new FileOutputStream(file); 
            bitmap1.compress(Bitmap.CompressFormat.JPEG, 100, output);
            output.flush();
            output.close(); } catch (Exception e) { // TODO Auto-generated catch block
            e.printStackTrace(); }

Problem will be discussed in Comment section.

About the author

Generic Bytes

Hi! we are from Generic Bytes an aspiring bloggers with an obsession of things tech.This blog is dedicated to people who want to learn the technology.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *