How can I display all images from a specific folder on android gallery like, for example, whatapp does. I`m using MediaScannerConnectionClient
File folder = new File("/sdcard/myfolder/");
allFiles = folder.list();
SCAN_PATH=Environment.getExternalStorageDirectory().toString()+"/myfolder/"+allFiles[0];
@Override
public void onScanCompleted(String path, Uri uri) {
try {
if (uri != null) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
startActivity(intent);
}
} finally {
conn.disconnect();
conn = null;
}
}
private void startScan() {
if (conn != null) {
conn.disconnect();
}
conn = new MediaScannerConnection(this, this);
conn.connect();
}
@Override
public void onMediaScannerConnected() {
conn.scanFile(SCAN_PATH, "image/*");
}
But I`m getting a error at this point:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
startActivity(intent);
Specific here:
startActivity(intent);
Fail to get type for: content://media/external/images/media/267830 No Activity found to handle Intent
On onScanCompleted my path and uri parameters are not null.
You can use android.database.Cursor
Answer given by @Talha works good but it tries to open image using image app options. If you want to just refresh gallery with folder in sd card you can modify code as below for SingleMediaScanner
And in button click loop over each file you get from:
And pass that to SingleMediaScanner one at time.
It worked in my case.
Hi you can use the code below, i hope it helps you .
You should add Grid view Adapter class.
Another Class GridView Adapter :
Activity:
activity_gallery_picture:
Another activity Layout :