Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve Picasa Image for Upload from Gallery

Tags:

android

picasa

I am working on an activity and associated tasks that allow users to select an image to use as their profile picture from the Gallery. Once the selection is made the image is uploaded to a web server via its API. I have this working regular images from the gallery. However, if the image selected is from a Picasa Web Album nothing is returned.

I have done a lot of debugging and narrowed the problem down to this method.

public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    //cursor is null for picasa images
    if(cursor!=null)
    {
        int column_index = cursor
        .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }
    else return null;
}

Picasa images return a null cursor. MediaStore.Images.Media.DATA is not null for them, however. It only returns an #id, so I am guessing that there is no actual bitmap data at the address. Are Picasa images stored locally on the device at all?

I also noticed from the documentation that MediaStore.Images.ImageColumns.PICASA_ID exists. This value exists for selected picasa images but not other gallery images. I was thinking I could use this value to get a URL for the image if it is not store locally but I can not find any information about it anywhere.

like image 820
dbaugh Avatar asked May 10 '11 01:05

dbaugh


People also ask

How do I retrieve my Picasa photos?

Where can I find my photos? If you have photos or videos in a Picasa Web Album, the easiest way to still access, modify and share most of that content is to log in to Google Photos. Your photos and videos will already be there.

Where are Picasa pictures stored?

Picasa stores data about pictures in 3 locations: the photo files themselves, inside . picasa. ini files, and in the Picasa database.

How do I transfer my Picasa photos to a new computer?

The good news, you don't have to. Moving your Google Picasa to a new computer is simple as long as you first copy all your photos and, Picasa is installed under the same user paths as your old system.


2 Answers

I have faced the exact same problem,
Finally the solution I found, was to launch an ACTION_GET_CONTENT intent instead of an ACTION_PICK, then make sure you provide a MediaStore.EXTRA_OUTPUT extra with an uri to a temporary file. Here is the code to start the intent :

public class YourActivity extends Activity {
    File mTempFile;
    int REQUEST_CODE_CHOOSE_PICTURE = 1;

    (...)
    public showImagePicker() { 
        mTempFile = getFileStreamPath("yourTempFile");
        mTempFile.getParentFile().mkdirs();
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
        intent.setType("image/*");
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempFile));
        intent.putExtra("outputFormat",Bitmap.CompressFormat.PNG.name());                       
        startActivityForResult(intent,REQUEST_CODE_CHOOSE_PICTURE);
    }

    (...)
}

You might need to mTempFile.createFile()

Then in onActivityResult, you will be able to get the image this way

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    case REQUEST_CODE_CHOOSE_PICTURE:
                Uri imageUri = data.getData();
                if (imageUri == null || imageUri.toString().length() == 0) {
                    imageUri = Uri.fromFile(mTempFile);
                    file = mTempFile;
                }
                                    if (file == null) {
                                       //use your current method here, for compatibility as some other picture chooser might not handle extra_output
                                    }
}

Hope this helps

Then you should delete your temporary file on finish (it is in internal storage as is, but you can use external storage, I guess it would be better).

like image 70
darune Avatar answered Oct 31 '22 07:10

darune


Why are you using the managedQuery() method? That method is deprecated.

If you want to convert a Uri to a Bitmap object try this code:

public Bitmap getBitmap(Uri uri) {

    Bitmap orgImage = null;
    try {
        orgImage = BitmapFactory.decodeStream(getApplicationContext().getContentResolver().openInputStream(uri));
    } catch (FileNotFoundException e) {
        // do something if you want
    }
    return orgImage;
}
like image 40
erkas Avatar answered Oct 31 '22 06:10

erkas