-1

Hello i make applicaiton with ss the phone screen, but this application store all photos on Local files in internal storage and every photo was not showing when i open my gallery in phone.

So how to store every photo in Gallery folders?

Here i take the SS

private void takeAScreenshot() {
    Date now = new Date();
    android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
    try {
        String mPath = Environment.getExternalStorageDirectory().toString()
                + "/" + now + ".jpg";
        View v1 = getWindow().getDecorView().getRootView();
        v1.setDrawingCacheEnabled(true);
        Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
        v1.setDrawingCacheEnabled(false);
        File imageFile = new File(mPath);
        FileOutputStream outputStream = new FileOutputStream(imageFile);
        int quality = 100;
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
        outputStream.flush();
        outputStream.close();
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

i check the permissions

i also find where is saved files from aparat:

/storage/emulated/0/DCIM/Camera/img_name.jpg

I find this, and this working:

ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis());
            values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
            values.put(MediaStore.MediaColumns.DATA, mPath)

but images is save on gallery folders and internal storage, Help

Rodriquez
  • 981
  • 1
  • 7
  • 21
  • check http://stackoverflow.com/questions/2169649/get-pick-an-image-from-androids-built-in-gallery-app-programmatically and http://blog.kupriyanov.com/2010/02/solved-android-save-image-to-media.html – Sreehari Oct 04 '16 at 06:42

2 Answers2

2

Use MediaScanner after saving it.

private void takeAScreenshot() {
        Date now = new Date();
        android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
        try {
            String mPath = Environment.getExternalStorageDirectory().toString()
                    + "/" + now + ".jpg";
            View v1 = getWindow().getDecorView().getRootView();
            v1.setDrawingCacheEnabled(true);
            Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
            v1.setDrawingCacheEnabled(false);
            File imageFile = new File(mPath);
            FileOutputStream outputStream = new FileOutputStream(imageFile);
            int quality = 100;
            bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        MediaScannerConnection.scanFile(ActivityName.this,
                new String[]{imageFile.toString()}, null,
                new MediaScannerConnection.OnScanCompletedListener() {
                    public void onScanCompleted(final String path, final Uri uri) {
                        ActivityName.this.runOnUiThread(new Runnable() {
                            public void run() {
                                Intent shareIntent = new Intent();
                                shareIntent.setAction(Intent.ACTION_SEND);
                                shareIntent.putExtra(Intent.EXTRA_STREAM,
                                        uri);
                                shareIntent.setType("image/jpeg");
                                startActivity(Intent.createChooser(shareIntent,
                                        "choose one"));
                            }
                        });
                    }
                });
    }
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41
0

Try adding this:

MediaStore.Images.Media.insertImage(getContentResolver(), yourBitmap, yourTitle , yourDescription);

Fill in your details for yourBitmap, yourTitle, and yourDescription, or just leave it as "".

Mujammil Ahamed
  • 1,454
  • 4
  • 24
  • 50