Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6817287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:02:01+00:00 2026-05-26T21:02:01+00:00

My Android app opens images and makes manipulations on them. My Activity requests an

  • 0

My Android app opens images and makes manipulations on them. My Activity requests an image to be opened as follows:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
                                            "Complete action using"),
                                            PICK_FROM_FILE);

On doing this, it launches a dialog with three to four options, like the ES File Explorer: Files, Gallery, etc.

I wish to read this as a Bitmap using BitmapFactory.decodeFile(path).

When I choose the file from ES File Explorer, the path is computed like this:

String path = imageData.getData().getPath();

However, this does not work for choosing an image from the Gallery or Files, where the value of path is /external/images/media/38 for example.

So I put a check, to convert such a path that begins with external using:

if (path.startsWith("/external")) {
  path = getFilePathFromUri(imageData.getData());
}

private String getFilePathFromUri(Uri uri) {
  Cursor cursor = managedQuery(uri,
                               new String[] { MediaStore.Images.Media.DATA },
                               null, null, null);
  int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
  cursor.moveToFirst();

  return cursor.getString(column_index);
}

This converts the above path to /mnt/sdcard/dcim/Camera/2011-11-13_15-33-24_304.jpg and now this works for BitmapFactory.decodeFile(path).

I understand that hardcoding such a check (/external) is not a good idea, is there a better, perhaps generic way to resolve the format of the URI returned in the Intent?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:02:02+00:00Added an answer on May 26, 2026 at 9:02 pm

    I understand that hardcoding such a check (/external) is not a good idea, is there a better, perhaps generic way to resolve the format of the URI returned in the intent?

    imageData.getData() returns a Uri. If its path starts with file:// (this is what most file managers will return), then the uri represents a file. Another option is uri represents a content item (this is what Gallery will return), in this case its path starts with content:// and you should call ContentProvider for an actual image file path (as you do in your sample). So I think you could go with something like this:

    Uri uri = imageData.getData();
    String scheme = uri.getScheme();
    if ("file".equals(scheme)) {
        // process as a uri that points to a file
    } else if ("content".equals(scheme)) {
        // process as a uri that points to a content item
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Android App I send email messages with images attached. Using the Intent
My android app project need to add a new function of saving the click
I'm new with android, and I have to make improvements for an existing app.
I'm writing an image editor in Android. So far it has a single activity.
I am new in android field. I am working on to display two images
I have this code in my app.js file in android and an images folder
I'm having trouble in making unrepeating random images on my Android App. Let's say
I'm having trouble in making unrepeating random images on my Android App. Let's say
I have read this link :Open an image in Android's built-in Gallery app programmatically
I'm new here on stackoverflow. I have a little problem with my Android app,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.