-3

I am building an app that calls for the camera, take a photo and save the photo in an internal storage directory. So far I have done that part and I already create my image file path. I have couple of images that I took from my camera and I save in that file directory, my Question is I want to Display those Image In a new Activity class Image Holder. How can I do it?

Zombie
  • 404
  • 10
  • 18

2 Answers2

1

Send the file path with the selected image name as an intent to the new Activity by a click or any event listener used to start the new Activity. Then, retrieve the image with the file path and the image name sent in the intent from the initial activity. Please add "android.permission.READ_EXTERNAL_STORAGE" in the manifest file.

public static void downloadImage(String fileName, ImageView image, Context context){

    File downloadFolder = Environment.getExternalStorageDirectory();
    File dir = new File(downloadFolder+ "/PopularMovie/");
    Uri downloadPath = Uri.fromFile(new File(dir, "/" + fileName + ".png/"));

    if (downloadPath.toString() != null){
        Picasso.with(context).load(downloadPath).placeholder(R.drawable.placeholder_image).into(image);

    } else {
        Toast.makeText(context, "There is no image of this name saved",
                Toast.LENGTH_LONG).show();
    }
}

Please note, I have used Picasso library, your application may not be be using Picasso. You can modify the code to suit your case. Also, I loaded the image into an ImageView.

Since you said you know your file path with the file name, you may not need to write the above code but simply just call Picasso as below;

if (downloadPath.toString() != null){
  Picasso.with(context).load(downloadPath).placeholder(R.drawable.placeholder_image).into(image);

} 
1

Save your image in a particular path and from Next activity call you image with the same path and with saved image name. Check out the links below

might help you.

https://stackoverflow.com/a/7266616/8311908

http://www.zoftino.com/android-capture-image-from-camera-and-save

https://stackoverflow.com/a/4182060/8311908

https://www.androidbegin.com/tutorial/android-display-images-from-sd-card-tutorial/

MazRoid
  • 145
  • 1
  • 12