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 6347693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:16:09+00:00 2026-05-24T21:16:09+00:00

I have some code in my app that works well for opening the gallery

  • 0

I have some code in my app that works well for opening the gallery (from within my app), selecting a photo, and uploading it.

I have made a fair attempt at integrating handling for intents with EXTRA_STREAMs attached, such as those generated by the “share” button in the gallery.

This works on my Droid X and it works on the emulator.

Today, I got an error report from a user; the cursor I used to pull the photo out of the MediaStore returned null when I asked it to return me the resource referred to in the EXTRA_STREAM parameter. The code had already passed through the point where it had verified that the Intent had an EXTRA_STREAM attached, and the user told me that they were using the “share” option from the gallery.

Their device was:

OS version: 2.3.3(10 / GRI40)
Device: HTC PG86100

What gives?

Why would the HTC gallery send me an Intent with an EXTRA_STREAM that I can’t access?

Are there any other reasons that a cursor would return null?

String[] filePathColumn = {MediaColumns.DATA};

Uri selectedImageUri;

//Selected image returned from another activity
if(fromData){
    selectedImageUri = imageReturnedIntent.getData();
} else {
    //Selected image returned from SEND intent

    // This is the case that I'm having a problem with.
    // fromData is set in the code that calls this; 
    // false if we've been called from an Intent that has an
    // EXTRA_STREAM
    selectedImageUri = (Uri)getIntent().getExtras().get(Intent.EXTRA_STREAM);
}

Cursor cursor = getContentResolver().query(selectedImageUri, filePathColumn, null, null, null);
cursor.moveToFirst();  // <-- NPE on this line
  • 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-24T21:16:11+00:00Added an answer on May 24, 2026 at 9:16 pm

    It turns out that many apps will send EXTRA_STREAMs with the image/* mime type, but not all of them use the gallery’s content provider.

    The ones that were generating a null pointer exception (as above) were cases in which I was trying to read from the content provider when I was given a file:// EXTRA_STREAM.

    The code that works is as follows:

    String filePath;
    String scheme = selectedImageUri.getScheme(); 
    
    if(scheme.equals("content")){
        Cursor cursor = getContentResolver().query(selectedImageUri, filePathColumn, null, null, null);
        cursor.moveToFirst(); // <--no more NPE
    
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    
        filePath = cursor.getString(columnIndex);
    
        cursor.close();
    
    } else if(scheme.equals("file")){
        filePath = selectedImageUri.getPath();
        Log.d(App.TAG,"Loading file " + filePath);
    } else {
        Log.d(App.TAG,"Failed to load URI " + selectedImageUri.toString());
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have some code that works and it's a Win32 app with a GUI,
I have a standalone Java app that has some licensing code that I want
I have some code that runs a cmd command in C# which works really
I have some code like this in a winforms app I was writing to
We have a J2EE app built on Struts2+spring+iBatis; not all DAO's use iBatis...some code
I have some code which collects points (consed integers) from a loop which looks
I have some code in a javascript file that needs to send queries back
I have some code that gives a user id to a utility that then
I have an app that performs some calculations based on data arriving on a
I have some component code that I'd like to in a CakePHP Task, but

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.