Open all the images in the folder (SD card) right away when you press the button

What I want: pressing a button should open all the images that are in a specific folder on the SD card.

What happens: if the folder has more than one image, then the application shows only one image.

Click the Method Code button:

private void showGallery() {

    if ((personName.getText().toString() != null && !personName.getText().toString().isEmpty())
            && (mobileNo.getText() != null && !mobileNo.getText().toString().isEmpty())) {

        File folder = new File(Environment.getExternalStorageDirectory(),
                    photoPath + personName.getText().toString() + "_" + mobileNo.getText().toString() + "/");

        File[] allFiles = folder.listFiles();
        if (allFiles != null && allFiles.length > 0) {
            for (File child : allfiles) {
                new SingleMediaScanner(getActivity(), child);
            }
        }
    }    
}

SingleMediaScanner Code:

public class SingleMediaScanner implements MediaScannerConnection.MediaScannerConnectionClient {

        private MediaScannerConnection mMs;
        private File mFile;

        public SingleMediaScanner(Context context, File f) {
            mFile = f;
            mMs = new MediaScannerConnection(context, this);
            mMs.connect();
        }

        public void onMediaScannerConnected() {
            mMs.scanFile(mFile.getAbsolutePath(), "image/*");
        }

        public void onScanCompleted(String path, Uri uri) {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setData(uri);
            startActivity(intent);
            mMs.disconnect();
        }
    }
}
+4
source share
1 answer

Use the Swipable cards library (Tinder like). This will show a stack of all images. Below is the link for you: https://android-arsenal.com/details/1/222

0

All Articles