0

Im building a pp for photo editing. i want to create my app folder in gallery and when user click on save button the images should be saved to my app specified folder in gallery, i make it possible with media storage with this line values.put("_data", file.getAbsolutePath());, BUT the problem is that these images in gallery are not showing, they are showing a 404 type error, i think this is a permission issue, but im storing the file in to my app specified folder with getExternalFileDir() than im showing this folder in gallery why there is a permission issue as im working in my app specific folder, here im sharing my code

    String resultPath = getExternalFilesDir(null)+ getString(R.string.directory) + 
    System.currentTimeMillis() + ".jpg";

       File file =  new File(resultPath);
        file.mkdirs();
        try {
            OutputStream fileOutputStream = new FileOutputStream(file);
            savedBitmap.compress(CompressFormat.JPEG, 100, fileOutputStream);
            fileOutputStream.flush();
            fileOutputStream.close();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
        savedBitmap.recycle();


        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, "Photo");
        values.put(MediaStore.Images.Media.DESCRIPTION, "Edited");
        values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis ());
        values.put(MediaStore.Images.ImageColumns.BUCKET_ID, file.toString().toLowerCase(Locale.US).hashCode());
        values.put(MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, file.getName().toLowerCase(Locale.US));
        values.put("_data", file.getAbsolutePath());

        ContentResolver cr = getContentResolver();
        cr.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Mubashir Murtaza
  • 327
  • 2
  • 14
  • It is unclear what you consider to be the android gallery. – blackapps Apr 20 '20 at 07:14
  • I solved my problem, As you can see in my code i was making a file from a string path, that is not correct , i just save my file from string "resultpat" and the file is saved at app specicfic folder than i use File file = new File(resultPath); so from file i can put some meta data in MediaStorage like this :: values.put(MediaStore.Images.ImageColumns.BUCKET_ID, file.toString().toLowerCase(Locale.US).hashCode()); And at last i did it like : values.put("_data", file.getAbsolutePath()); AND contentresolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); – Mubashir Murtaza Apr 22 '20 at 08:36
  • to show images in gallery we need to put some meta data! – Mubashir Murtaza Apr 22 '20 at 08:38
  • @blackapps what would you consider to be Android gallery? – Sermilion Aug 02 '23 at 13:42
  • Im not aware of an Android gallery. – blackapps Aug 02 '23 at 14:18

0 Answers0