Search code examples
androidimagevideouniversal-image-loader

Get correct File uri from file path in sdcard when using in Universal Image Loader


Currently, I use the [Universal Image Loader] library to load some files from the sd card.
I want to get the following URI from a file path: file:///mnt/sdcard/image.png

I already tried this way to get file URI: Uri uri = Uri.fromFile(mAlFileList.get(i));

But the file URI already modified to file:///mnt/sdcard/%5B40k%5D/20141014_232337.jpg

When I use a special character in the folder name, is : [40k] - this is the name of this one %5B40k%5D.

What I want is get this file URI: file:///mnt/sdcard/[40k]/20141014_232337.jpg
But yet I don't know how to get the correct thing.

Please help me out.

P.S.:

  • It also apply for a case in that the folder name also includes a space character, like this: My Folder (it was changed to %20, but it is not what I want)
  • Actually, If I don't use any special character, the library can load the files correctly.

The accepted URI from library:

"http :// site.com/image.png" // from Web
"file:///mnt/sdcard/image.png" // from SD card
"file:///mnt/sdcard/video.mp4" // from SD card (video thumbnail)
"content://media/external/images/media/13" // from content provider
"content://media/external/video/media/13" // from content provider (video thumbnail)
"assets://image.png" // from assets
"drawable://" + R.drawable.img // from drawables (non-9patch images)
  • Code load media files :

                imageLoader.displayImage(
                Uri.fromFile(new java.io.File(FILE_PATH)).toString()
                ,
                markableImageView, mDio,
                new SimpleImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String imageUri, View view) {
                    }
    
                    @Override
                    public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                    }
    
                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                        if (loadedImage != null & view != null) {
                            ((ImageView) view).setImageBitmap(Bitmap.createScaledBitmap(
                                    loadedImage,
                                    mContext.getResources().getInteger(R.integer.width_file_view),
                                    mContext.getResources().getInteger(R.integer.height_file_view),
                                    false));
                        }
                    }
                }, new ImageLoadingProgressListener() {
                    @Override
                    public void onProgressUpdate(
                            String imageUri, View view, int current, int total) {
                    }
                });
    

Solution

  • No way to get this file:///mnt/sdcard/[40k]/20141014_232337.jpg.

    So I should try the other way is get Content Uri, like content://media/external/images/media/24415, not File Uri as example in above.