简体   繁体   English

在android中显示图像sd卡特定的文件夹

[英]show images sd card specific folder in android

I try to show images sd card specific folder.I wrote some code and i can show all images in my divice in Gridview.This is my source code 我尝试显示图像sd卡特定的文件夹。我写了一些代码,我可以在Gridview的设备中显示所有图像。这是我的源代码

 private void fetchGalleryImages() {
    final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID};//get all columns of type images
    final String orderBy = MediaStore.Images.Media.DATE_TAKEN;//order data by date
    Cursor imagecursor = managedQuery(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
            null, orderBy + " DESC");

    galleryImageUrls = new ArrayList<String>();//Init array



    for (int i = 0; i < imagecursor.getCount(); i++) {
        imagecursor.moveToPosition(i);
        int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);//get column index
        galleryImageUrls.add(imagecursor.getString(dataColumnIndex));//get Image from column index
        System.out.println("Array path" + galleryImageUrls.get(i));
    }


}

how i can wrote my code to can show images only sdcard/myfolder/ (only myfolder images)? 我如何编写代码以仅显示sdcard / myfolder /(仅显示myfolder图像)? if anyone knows solution please help me thanks 如果有人知道解决方案,请帮助我,谢谢

To get the image from specific file use select and select arg like this for you it will be Image in place of Audio 要从特定文件中获取图像,请选择并选择arg这样,它将是Image代替Audio

 String selection = MediaStore.Audio.Media.DATA + "=?";

        String[] selectionArgs = new String[]{""+file_uri};

And here file_uri is of string type just declare a string named file_uri=your file name . 在这里file_uri是字符串类型,只需声明一个名为file_uri=your file name的字符串。

So your code will be like this 所以你的代码会像这样

 MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, selection,
        selectionArgs, orderBy + " DESC");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM