vishal dharankar
vishal dharankar

Reputation: 7746

Open built in gallery app with an album

How to open inbuilt gallery app with a specific album opened on screen ?

I know this code can be used for launching gallery app , but how to filter a specific album ? or open it ?

Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);

Upvotes: 2

Views: 719

Answers (1)

Sohail Zahid
Sohail Zahid

Reputation: 8149

Assume your photos ares stored at youCam folder or it can be any folder

If you are compiling against API 23 or Greater then get runtime permision READ_EXTERNAL_STORAGE

File file = new File(Environment.getExternalStorageDirectory().getPath() + "/youCam);

File[] listFile = file.listFiles();
new HomeScreen.SingleMediaScanner(HomeScreen.this, listFile[0]);
...
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(), null);
        }

        public void onScanCompleted(String path, Uri uri) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(uri);
            startActivity(intent);
            mMs.disconnect();
        }

    }

This will open you all images in that folder in default gallery.

Upvotes: 1

Related Questions