我想要的是:单击按钮应该打开SD卡上特定文件夹中的所有图像.
发生了什么:如果文件夹有多个图像,则应用程序仅显示单个图像.
按钮单击方法代码:
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代码:
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();
}
}
}