在同一文件夹中查询所有文件时,不显示位图的存储文件 [英] Stored File of Bitmap is not displayed when querying for all files in the same folder

查看:158
本文介绍了在同一文件夹中查询所有文件时,不显示位图的存储文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我存储在移动的SD卡一个位图,然后我有列出,我救了我的位图文件夹中的所有文件present另一种方法。问题是,存储图像的时候,即使我检查他们是否真的present的文件夹中,我的codeS从该文件夹列表中的图像不回这些图像,通常后显示他们几次我虽然使用的应用程序。谁能帮助我?你可以找到我的$ C $以下CS。

I am storing a Bitmap in the SD card of the mobile, then I have another method that lists all File present in the folder where I saved my Bitmap. The problem is that when the images are stored, and even though I checked whether they are really present in the folder, my codes to list images from that folder doesn't return those images, it usually shows them after a few times I utilise the app though. Can anyone help me with this? You can find my codes below.

这是用于存储位图

imagesFolder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "ILoveKitties");

if(!imagesFolder.exists())
    imagesFolder.mkdirs();
int imageNum;
if(imagesFolder.list()==null)
    imageNum = 1;
else
    imageNum = imagesFolder.list().length + 1;

String fileName = "appname_" + String.valueOf(imageNum) + ".jpg";
output = new File(imagesFolder, fileName);
while(output.exists()){
    imageNum++;
    fileName = "appname_" + String.valueOf(imageNum) + ".jpg";
    output = new File(imagesFolder, fileName);
}

OutputStream fOut = new FileOutputStream(output);
merged.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.flush();
fOut.close();
fOut = null;
saved = true;
savedFilePath = "file://" + output.getCanonicalPath();

这是该文件夹中检索文件的列表

And this is for retrieving a list of files in the folder

boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
if(isSDPresent) {
    String[] projection = {MediaStore.Images.Media.DATA};
    cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            projection, 
            MediaStore.Images.Media.DATA + " like ? ", 
            new String[] {"%APPNAME%"}, 
            null);
    columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

    File testFileAvailability;
    for(int i=cursor.getCount()-1; i>=0; i--){
        cursor.moveToPosition(i);
        // get image filename
        testFileAvailability = new File("file://" + cursor.getString(columnIndex));
        if(testFileAvailability.exists()){
            listImagePath.add("file://" + cursor.getString(columnIndex));
        }

    }
}

我然后使用路径来显示图像。

I then use the path to display the images.

推荐答案

好吧,一旦你保存文件中设备存储然后只需引发媒体扫描仪插入在MediaStore文件条目,然后你的应用程序应该是能够得到文件的路径。

Ok, once you store file in Device Storage then just trigger the Media Scanner to insert File Entry in MediaStore then your application should be able to get the file path.

要引发媒体扫描仪使用低于code:

To trigger Media Scanner use below code:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));

其实,你必须引发媒体扫描仪获得你所当前存储的文件条目。
Android设备做时,其重新启动。或者您启动任何机相机或相册应用程序(如果他们付诸实施)。

Actually, You have to trigger Media Scanner to get the file entry which you have stored currently. Android device do when its reboot. Or You launch any Native Camera or Gallery Application(If they implemented it).

这篇关于在同一文件夹中查询所有文件时,不显示位图的存储文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆