0

I am working on app that store its image from resource to gallery. with the below code, it does not give an error but do not work. help me through this.

RelativeLayout fulllayout;
File root = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "/ZXMCO Images");
 fulllayout = (RelativeLayout) findViewById(R.id.layout);

public void save()
{
    fulllayout.setDrawingCacheEnabled(true);
    fulllayout.buildDrawingCache();
    Bitmap localBitmap = fulllayout.getDrawingCache();
    saveToInternalStorage(localBitmap);
}

private void saveToInternalStorage(Bitmap bitmapImage){

        File pictureFile = getOutputMediaFile();

        try {
            FileOutputStream fos = new FileOutputStream(pictureFile);
            bitmapImage.compress(Bitmap.CompressFormat.PNG, 90, fos);
            fos.close();
        } catch (FileNotFoundException e) {
            Log.d(TAG,"File not found: " + e.getMessage());
        } catch (IOException e) {
            Log.d(TAG, "Error accessing file: " + e.getMessage());
        }

     }
private File getOutputMediaFile() {

    if (! root.exists()){
        root.mkdirs();
        }


    String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmm").format(new Date());
    File mediaFile;
    String mImageName="MI_"+ timeStamp +".jpg";
    mediaFile = new File(root.getPath() + File.separator + mImageName);
    return mediaFile;
}

It just show nothing. run without an error but could not find the image in gallery.

Ankita Shah
  • 1,866
  • 16
  • 31
Man Xoor
  • 35
  • 2
  • 11
  • `app that store its image from resource to gallery`. Impossible. The Gallery app is an app. Not a storage place. It happens that the Gallery app likes to show all pictures on your device. Please rephrase your goal. – greenapps Dec 13 '16 at 12:54
  • i am storing in a storage, but it does not show up on gallery. – Man Xoor Dec 13 '16 at 13:03
  • https://stackoverflow.com/questions/32789157/how-to-write-files-to-external-public-storage-in-android-so-that-they-are-visibl – CommonsWare Dec 13 '16 at 13:03

1 Answers1

0

I Think the problem here is the Gallery didn't know that theres new images is stored on the device so we will need to notify it

There's two way to do that

Pre - Kitkat

using Boradcast

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));

Kitkat

You Can user the MediaScannerConnection to scan the new files

 MediaScannerConnection.scanFile(context, new String[]{imageURL}, null,implment Listener Here);
Ahmed Mahmoud
  • 111
  • 1
  • 7