本文介绍了file.exists()返回android系统中现有的档案造假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,用户可以从SD卡中选择图像并设置档案图片。一切正常,但是当用户在WhatsApp的文件夹,从SD卡图像选择图像不能去codeD。

In my app user can select image from sdcard and set as profile picture. Everything is working fine but when user selects image from whatsapp folder from sdcard image can not decoded.

我使用以下code脱在ImageView的code文件和显示。

I am using following code to decode file and display in ImageView.

if (imgFile.exists()) {

Bitmap myBitmap = BitmapFactory.decodeFile(imgFile
        .getAbsolutePath());

imgProfilePic.setImageBitmap(myBitmap);
myBitmap = null;
System.gc();
Runtime.getRuntime().gc();

}

我正在选择映像路径 /存储/ sdcard0 / WhatsApp的/媒体/ WhatsApp的图像/ IMG-20130804-WA0000.jpg 并在SD卡存在但 file.exists 始终返回false。
如果用户在其他文件夹中选择图像,而不是WhatsApp的正常工作。

I am getting selected image path /storage/sdcard0/WhatsApp/Media/WhatsApp Images/IMG-20130804-WA0000.jpg and it exists in sdcard but file.exists always returns false.It works fine if user selects image from other folders rather than whatsapp.

更新

我下面像

1. click on profilepic(imageview).
2. select options(from camera,galerry,or edit)
3. open selected or captured image in CropImage Activity.
4. display cropped image.

Anyhelp将大大AP preciated..Thanks。

Anyhelp would be greatly appreciated..Thanks.

推荐答案

我修改图像。我觉得这可能是问题。所以我做了什么?

I was modifying image of other apps. I think this might be the problem. So what I did ?

1. select image and get path in onActivityResult()
2. copy image from this path in temp file using below code
3. use temp file for cropping and other processing

private void copyFile(File sourceFile, File destFile) throws IOException {
    if (!sourceFile.exists()) {
        return;
    }

    FileChannel source = null;
    FileChannel destination = null;
    source = new FileInputStream(sourceFile).getChannel();
    destination = new FileOutputStream(destFile).getChannel();
    if (destination != null && source != null) {
        destination.transferFrom(source, 0, source.size());
    }
    if (source != null) {
        source.close();
    }
    if (destination != null) {
        destination.close();
    }

}

希望这可以帮助别人。

Hope this may help someone else.

这篇关于file.exists()返回android系统中现有的档案造假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 17:42