Skip to content Skip to sidebar Skip to footer

Getting Incorrect File Path For Some Images In Android ( Android One Device Or Which Allow To User Save Images Into Cloud)

I am trying to get the images from sd-card and displaying it into imageview. But My problem is that here some time I am getting correct path for some images but for some images, i

Solution 1:

This issue will happen only "android-one" phone or "the devices which allow to user to save the images into cloud". In this case, when we clicked on camera icon for selecting the images from the gallery. since some of the images may be uploaded in Goolge_Cloud and display us in gallery. there was difficulty to get the image path. because i was getting the image path from sdcard or internally memory and then uploading in our server. so i was getting the image url of google cloud like as

"https://lh5.googleusercontent.com/dOx-Uo-m3bgjHgSQ8YpxUl8DHuqjoSdpYeK8OGAW8ac=s0-d" 

when you will click on it, it will display the image which is in cloud.

so I fixed it like as

// if we will get the cloud url then

1)it will download it from cloud. ( a small loading bar will be displaying during download)
2)display in image view ( hide the loading bar once downloaded )
3)save temp into sdcard
4)take the path of this image 
5)upload it into server
6)remove this temp image which was saved into sdcard 

here is my code

if (selectedImageUri.getLastPathSegment().contains("https://lh5.googleusercontent.com"))
                    doDownloadTaskAndGetSaveImage(selectedImageUri.getLastPathSegment());
                else // do as you are doing

some above steps task

private void doDownloadTaskAndGetSaveImage(String lastPathSegment) {

    // show the progressBar.
    imgeLoadingBar.setVisibility(View.VISIBLE);
    //show the ImageView.
    imagePreview.setVisibility(View.VISIBLE);

    AQuery aq = new AQuery(imagePreview);
    aq.hardwareAccelerated11();
    aq.id(imagePreview).image(lastPathSegment, false, false, 0, 0,
            new BitmapAjaxCallback() {

                @Override
                public void callback(String url, ImageView iv, Bitmap bm,
                        AjaxStatus status) {

                    System.out.println("url = " + url);

                    File file = new File(Environment
                            .getExternalStorageDirectory(), "image.jpg");

                    // delete exits image first.
                    System.out.println("file.exists() = " + file.exists());
                    if (file.exists())
                        file.delete();

                    // save this image into sdcard for temp.
                    try {
                        FileOutputStream fos = new FileOutputStream(file);
                        boolean isSaved = bm.compress(CompressFormat.JPEG,
                                75, fos);
                        if (isSaved) {
                            filePathImage1 = file.getPath();
                            System.out.println("get path = "
                                    + filePathImage1);
                        }
                        fos.flush();
                        fos.close();
                        displayInImageViewAndRotateIfNeed(filePathImage1,
                                iv);

                        // hide the progressBar.
                        imgeLoadingBar.setVisibility(View.GONE);

                    } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }

            });

}

NOTE I am using this library for downloading the image and getting callback. https://code.google.com/p/android-query/wiki/ImageLoading


Post a Comment for "Getting Incorrect File Path For Some Images In Android ( Android One Device Or Which Allow To User Save Images Into Cloud)"