1

I have few wallpapers saved in drawable folder. I want save these images in wallpapers folder. For now my images are getting saved in camera folder. Using this code.

Bitmap w1 = BitmapFactory.decodeResource(getResources(),
                R.drawable.wallpaper03);

Images.Media.insertImage(getApplicationContext().getContentResolver(),
                w1, "", "");
Ahmed
  • 33
  • 7
  • possible duplicate of [Save image to sdcard from drawble resource on Android](http://stackoverflow.com/questions/10558053/save-image-to-sdcard-from-drawble-resource-on-android) – Nadeem Iqbal Apr 20 '15 at 09:04

3 Answers3

1

As I have understand your questions U need wallpapers directory in memory, U need to save your drawable images to that directory

Create wallpapers directory or folder , if not exist Create folder in Android

how to save images from drawable to phone memory save image to device memory

Community
  • 1
  • 1
Tarun Sharma
  • 824
  • 1
  • 11
  • 24
  • No i don't want create a new folder. Rather want to save it in the built in wallpaper folder of phone. Is it possible ? – Ahmed Apr 20 '15 at 09:13
  • yes it is possible. but you need to confirm that there is any wallpapers folder...... try to get name of folders exist in phone, using this link..... http://stackoverflow.com/questions/6917860/android-sd-card-directory-folders-name-list......... if there is wallpapers folder exist in list. then take path of that folder and save images to that folder... otherwise use above method – Tarun Sharma Apr 20 '15 at 10:50
1

Saving image to sdcard from drawble resource:

Bitmap bm = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher);

The path to SD Card can be retrieved using:

String extStorageDirectory = Environment.getExternalStorageDirectory().toString()+"/FOLDERNAME/";

Then save to sdcard on button click using:

File file = new File(extStorageDirectory, "ic_launcher.PNG");
    outStream = new FileOutputStream(file);
    bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
    outStream.flush();
    outStream.close();

Don't forget to add android.permission.WRITE_EXTERNAL_STORAGE permission.

a complete sample project: SAMPLE PROJECT

Nadeem Iqbal
  • 2,357
  • 1
  • 28
  • 43
1
  void Save(){  
String folder = "/sdcard/Pictures/MyAppFolder";
       Imageview  view = (ImageView)findViewById(R.id.cachesView);

          view.buildDrawingCache(); 

        Bitmap yourBitmap = view.getDrawingCache();  
          final File myDir = new File(folder);
                myDir.mkdirs();
                final Random generator = new Random();
                int n = 10000;
                n = generator.nextInt(n);
                final String fname = "StyleMe-" + n + ".png";
                File file = new File(myDir, fname);
                if (file.exists())
                    FileOutputStream out = new FileOutputStream(file);
                    yourBitmap.compress(CompressFormat.JPEG, 100, out);
                    out.flush();
                    out.close();
                    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                            Uri.parse("file://"
                                    + Environment.getExternalStorageDirectory()))); // this will refresh the gallery app.
                    Toast.makeText(getApplication(), "Image Saved", Toast.LENGTH_SHORT)
                            .show();
    }

please see

add this method in your class and on click button put

Save();

see here as answered by k0sh

Community
  • 1
  • 1
Keshav
  • 1,123
  • 1
  • 18
  • 36