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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:34:38+00:00 2026-06-02T19:34:38+00:00

I’m using these 2 classes to request and retrieve the picture from the Gallery.

  • 0

I’m using these 2 classes to request and retrieve the picture from the Gallery. This code works well in Gingerbread and below but in Honeycomb on my Xoom it fails.

The behavior I see it it writes a blank file but the gallery doesn’t write the chosen picture to that file. In addition, the file is not visible in Windows I have to go to the DDMS tab to see the file be created. It has rw access for owner and group but not everybody.

Adapted From: Retrieve Picasa Image for Upload from Gallery

public static class GetImage implements IIntentBuilderForResult {
    public String TypeFilter = "image/*";
    public boolean ForceDefaultHandlers = false;
    public Bitmap.CompressFormat CompressFormat = Bitmap.CompressFormat.PNG;

    private Intent intent = null;
    private String TemporaryImagePath = null;

    public void prepareIntent(Context context) {
        try {
            File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
            dir.mkdirs();
            File tempFile = new File(dir, "galleryresult-temp.png");

            //.createTempFile("GalleryResult", ".png");
            TemporaryImagePath = tempFile.getAbsolutePath();

            tempFile.getParentFile().mkdirs();

            tempFile.createNewFile();
            Logger.d("IsFile= " + tempFile.isFile());
            tempFile.setWritable(true, false);
            tempFile.setReadable(true, false);

            intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType(TypeFilter);

            if (ForceDefaultHandlers) {
                intent.addCategory(Intent.CATEGORY_DEFAULT);
            }

            final Uri uri = Uri.fromFile(tempFile);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
            final String formatName = CompressFormat.name();
            intent.putExtra("outputFormat", formatName);
        } catch (Exception e) {

        }
    }

    public Intent getIntent() {
        return intent;
    }

    public Bundle getResultBundle() {
        Bundle data = new Bundle();
        data.putString("transientImagePath", TemporaryImagePath);
        return data;
    }
}

public abstract static class GetImageResult extends ActivityResultHandlerHelper {

    public Bitmap bitmapResult = null;

    public void onPrepareResult() {
        bitmapResult = null;
        Uri imageUri = null;
        String filePath = null;
        boolean fromTransientPath = false;
        String tempFilePath = null;

        if(resultBundle != null) {
            tempFilePath = resultBundle.getString("transientImagePath");

            File tempFile = new File(tempFilePath);
            imageUri = Uri.fromFile(tempFile);
        }
        if(imageUri == null || imageUri.toString().length() == 0) {
            imageUri = data.getData();
        } else {
            fromTransientPath = true;
        }

        if(imageUri != null) {

            if(imageUri.getScheme().equals("file")) {
                filePath = imageUri.getPath();
            } else if(imageUri.getScheme().equals("content")) {
                filePath = findPictureFilePath(context, imageUri);
            }

            if(filePath != null) {
                bitmapResult = BitmapFactory.decodeFile(filePath);
                if(fromTransientPath) {
                    //File delTarget = new File(filePath);
                    //delTarget.delete();
                }
            }
        }
    }
}

public static final String findPictureFilePath(Context context, Uri dataUri) {
    String filePath = null;
    final String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = null;
    try {
        cursor = context.getContentResolver().query(dataUri, projection,
                null, null, null);
        int data_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        if (cursor.moveToFirst()) {
            filePath = cursor.getString(data_index);
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    return filePath;
}
  • 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-06-02T19:34:40+00:00Added an answer on June 2, 2026 at 7:34 pm

    Launch intent to get the photo.

    final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    activity.startActivityForResult(intent, requestCode);
    

    Accept the photo on return.

    final InputStream is = context.getContentResolver().openInputStream(intent.getData());
    final Bitmap imageData = BitmapFactory.decodeStream(is, null, options);
    is.close();
    

    This issue was so maddening that I wrote a whole article about how to do it properly. Or at least the best possible way.

    http://androidfragments.blogspot.com/2012/02/loading-bitmaps-from-gallery.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small

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.