How can i list all files created by my app in API 29+ scoped storage?

161 views Asked by At

I want to log files and directories created by my android app on above API level 29+, since listFiles() not working and giving null output. following code creates TestFolder and copies image into it, I want to read all images from it.

ContentResolver resolver = getContentResolver();
    ContentValues contentValues = new ContentValues();
    String RELATIVE_PATH = Environment.DIRECTORY_PICTURES + File.separator + "TestFolder";

    try{

        contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, System.currentTimeMillis()+".jpg");
        contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/jpg");
        OutputStream imageOutStream;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, RELATIVE_PATH);
        }

        Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
        Uri uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);

        imageOutStream = resolver.openOutputStream(uri);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, imageOutStream);
        imageOutStream.close();

        destTv.setText(uri.toString());

    }catch (Exception e){
        Log.e(TAG, "init: "+e );
    }
0

There are 0 answers