I have a decent set of code to handle the Intent, absolutely stock, using 
AsyncTask to process the result of the download.

This works perfectly when the selected photo is anywhere on the phone, but 
Gallery also shows my lovely collection of 27,000 photos. When I select an 
image from there, Android kindly downloads the picture onto the phone. 
However, nearly every time, that photo will fail to display - there is data 
there, but it fails trying to extract the bitmap, which for the moment I am 
using 

Watching what it is going on, my educated guess is that OnActivityResult 
returns with RESULT_LOAD_IMAGE and RESULT_OK after the file has been 
created locally, but not before the file has completed downloading. (I'm 
going to hack a time delay loop to test this theory).

Is this a) An Android/Gallery bug?
          b) The wrong event to monitor and there is actually another event 
emitted by the gallery process?
          c) The right event but there is some data in the intent.Data that 
I can check to find out if the downloaded file is complete (e.g. a embedded 
length and an actual length?)
          d) Working as designed and I should actually put in a hack to 
work around like a test every second to see if I finally get a picture 
(expensive!)?

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

        Log.i(TAG,"Begin onActivityResult");
        // When an Image is picked
        if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK
                && null != data) {
            // Get the Image from data
            Log.i(TAG, "Believe I have something useful to load");
            Uri selectedImage = data.getData();
            BackgroundGetImage doGetImage = new 
BackgroundGetImage(getActivity(),"Please wait...");
            doGetImage.delegate = this;
            doGetImage.execute(selectedImage);
        } else {
    Toast.makeText(getActivity(), "You haven't picked Image",
            Toast.LENGTH_LONG).show();
}
}


@Override
protected Bitmap doInBackground(Uri... image) {
    Log.i(TAG,"Getting image info");
    String[] filePathColumn = { MediaStore.Images.Media.DATA };

    // Get the cursor
    Cursor cursor = getContext().getContentResolver().query(image[0],
            filePathColumn, null, null, null);
    // Move to first row
    cursor.moveToFirst();

    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    if (columnIndex < 0) {
                 Log.i(TAG, "Invalid image");

        return null;
    }
    imgDecodableString = cursor.getString(columnIndex);
    cursor.close();
    Log.i(TAG, "Getting thumbnail");

    Bitmap ThumbImage = 
ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(imgDecodableString), 
THUMBSIZE, THUMBSIZE);
    if (ThumbImage != null) {
        Log.i(TAG, "Got thumbnail");

    } else {
        Log.i(TAG, "Thumbnail null");
    }
    return ThumbImage;

}

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/a0d315ce-9099-4858-901b-de32865e9312%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to