0

I'm trying to open an image using intent. The path of the image in my storage is /storage/emulated/0/nitp/download/logo.png.

My code is

Intent intent = new Intent();
intent.setAction(Intent.ACTION_DEFAULT);
intent.setDataandType(Uri.parse("/storage/emulated/0/nitp/download/logo.png"),"image/*");
startActivity(intent);

I also tried putting file://storage/emulated/0/nitp/download/logo.png and content://storage/emulated/0/nitp/download/logo.png

What is the path I should use?

Solved Have to use file:///storage/emulated/0/nitp/downloads/logo.png

Pablo Escobar
  • 393
  • 2
  • 16
  • It promt the "choose application" dialogue but the app I select to doesn't open. It closes immediately and I'm again in my app's activity – Pablo Escobar Jun 18 '16 at 06:23
  • what do you see on the logcat after calling `startActivity`? – pskink Jun 18 '16 at 06:23
  • also what is the output of `adb shell ls -l /storage/emulated/0/nitp/download/logo.png` ? – pskink Jun 18 '16 at 06:25
  • When I try add shell ls storage/emulated/0/nitp/downloads it says no such directory. But instead it shows that directory is /storage/sdcard0/nitp/downloads. – Pablo Escobar Jun 18 '16 at 06:50
  • Possible duplicate of [Open an image using URI in Android's default gallery image viwer](http://stackoverflow.com/questions/5383797/open-an-image-using-uri-in-androids-default-gallery-image-viwer) – Janki Gadhiya Jun 18 '16 at 06:54
  • @jannkigandhiya we have to use file:/// instead of file:// ty – Pablo Escobar Jun 18 '16 at 06:57

1 Answers1

0

For Pick image from media Storage or SD Card:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);

And For get the path of Image and set in ImageView:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
        Uri filePath = data.getData();
        try {
            //Getting the Bitmap from Gallery
            imgpath= MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
            //Setting the Bitmap to ImageView
            imageViewProfileImage.setImageBitmap(imgpath);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Hope this work.

Mahmudur Rahman
  • 638
  • 9
  • 25