仅在我的应用程序的默认库中显示图像

时间:2016-05-16 08:09:47

标签: android android-gallery

图片存储在/storage/emulated/0/policeSuites/

想要查看默认图库中policeSuites文件夹中的所有图片。

 public void openFolder() {

        File storageDir = Environment.getExternalStoragePublicDirectory("/Police photo suits");
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        Uri uri = Uri.parse(String.valueOf(storageDir));
        intent.setDataAndType(uri, "image/*");
        startActivity(Intent.createChooser(intent, "Open folder"));

    }

1 个答案:

答案 0 :(得分:0)

     public void openFolder() {

            File file = null;
            if (!Environment.getExternalStorageState().equals(
                    Environment.MEDIA_MOUNTED)) {
                Toast.makeText(this, "Error! No SDCARD Found!",
                        Toast.LENGTH_LONG).show();
            } else {
                file = new File(Environment.getExternalStorageDirectory()
                        .getPath() + "/" + getString(R.string.app_name));
            }
            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();
        }

    }