3

I have an activity that retrieves images from the device's gallery and uploads to a service. Now, for optimisation purposes, I would like to avoid uploading images that are on Picasa an just store their ID or URL for later retrieval.

So my question is, how do I retrieve that information. My intent code is pasted below and retrieves the URI of the image.

Intent galleryIntent = new Intent();
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_PICK);
startActivityForResult(galleryIntent, GALLERY_PIC_REQUEST);

I tried to look for the PICASA_ID (MediaStore.Images.Media.PICASA_ID), but by using the method above, it returns null. Any ideas?

4
  • Nobody? Can anyone give me some pointers about how I can retrieve the PICASA_ID from a picture showing on the gallery in albums marked with the Picasa logo? Is that even possible?
    – oviroa
    Aug 8, 2011 at 21:55
  • By picasa do you mean: picasa.google.com ? Aug 12, 2011 at 7:29
  • Well, not quite. The Android default image gallery displays albums from picasa connected to your google account.
    – oviroa
    Aug 12, 2011 at 17:16
  • 1
    The only solution I have found that actually works and covers different Android versions, picasa thumbnails and local files is: dimitar.me/…
    – Guy
    Jun 25, 2012 at 10:11

2 Answers 2

0
  • Launch an ACTION_GET_CONTENT intent instead of an ACTION_PICK

  • Provide a MediaStore.EXTRA_OUTPUT extra with an URI to a temporary file.


Add this to your calling activity:

File yourFile;

Now use this code to get Intent:

yourFile = getFileStreamPath("yourTempFile");
yourFile.getParentFile().mkdirs();
Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT, null);
galleryIntent .setType("image/*");
galleryIntent .putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(yourFile));
galleryIntent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.name());
startActivityForResult(galleryIntent, GALLERY_PIC_REQUEST);

MAKE SURE THAT yourFile is created

Also in your calling activity

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch(requestCode){
    case GALLERY_PIC_REQUEST:
        File file = null;
        Uri imageUri = data.getData();
        if (imageUri == null || imageUri.toString().length() == 0) {
            imageUri = Uri.fromFile(mTempFile);
            file = mTempFile;
            //this is the file you need! Check it
        }
        //if the file did not work we try alternative method
        if (file == null) {
            if (requestCode == 101 && data != null) {
                Uri selectedImageUri = data.getData();
                String selectedImagePath = getPath(selectedImageUri);
                //check this string to extract picasa id
            }
        }
    break;
    }
}

public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    if(cursor!=null)
    {
        int index = cursor
        .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(index);
    }
    else return null;
}
7
  • Hm, I had figured the first part out, but that is not what i am trying to do. I do not want to download the file from picasa locally, that is a very expensive bandwidth and resource heavy operation. I just need the picasa Id, so I can attach that to my data. I will try the second piece (if file == null) and if that works, than I have an answer. Thanks.
    – oviroa
    Aug 15, 2011 at 17:57
  • I looked at the answer and it looks like my question has not been understood. What I am trying to do is avoid downloading the picture from picasa in any way. Therefore storing it locally as a temp file does not do it. I am asking if there is any way to retrieve any information about that image (id, picasa url etc.) from the built in gallery/album.
    – oviroa
    Aug 15, 2011 at 18:51
  • Also, the solution above does not work, not on my N1. The image cannot be stored on the card, I geterrors and a null path: 08-15 18:35:03.747: ERROR/(11427): Not JPEG: /mnt/sdcard/DCIM/Camera/1313433294232.jpg 08-15 18:35:03.797: ERROR/(11427): Not JPEG: /mnt/sdcard/DCIM/Camera/1313433294232.jpg 08-15 18:35:03.847: ERROR/PicasaAPI(11427): getAlbums: unexpected status code 403 data: java.util.zip.GZIPInputStream@40554d48. Secondly, if I just do the file == null part, I get a path that contains a long number that is an ad-hoc UID but not connected to any picasa identification.
    – oviroa
    Aug 15, 2011 at 19:06
  • wasnt here: try to log.v("",imageUri) .. see what data is there! Aug 15, 2011 at 22:49
  • Here's what I get: 08-16 00:33:28.033: ERROR/CropImage(12825): Cannot save to uri file:///data/data/my.app.package/files/yourTempFile 08-16 00:33:28.113: WARN/MY LOG::URI(12896): file:///data/data/my.app.package/files/yourTempFile
    – oviroa
    Aug 16, 2011 at 0:35
-1
@Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        dir =new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/MyImages");
        dir.mkdir();
        filename = ("Image_" + String.valueOf(System.currentTimeMillis()) + ".poc");
    }

protected Uri getTempFile()
    {
        File file = new File(dir,filename);
        muri = Uri.fromFile(file);
        return muri;
     } 


    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        menu.add("Pick Image");
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) 
    {
         // TODO Auto-generated method stub
         super.onOptionsItemSelected(item);
         openOptionsChooseDialog();
         return true;
    }

 private void openOptionsChooseDialog()
    {
            AlertDialog.Builder builder = new AlertDialog.Builder(AppActivity.this).setTitle("Select Image").setItems(items, new DialogInterface.OnClickListener()
            {
                public void onClick(DialogInterface dialog, int item)
                {
                    Intent intent = new Intent();
   intent.setAction(Intent.ACTION_PICK);
                        intent.setType("image/*");
                        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
                        intent.putExtra(MediaStore.EXTRA_OUTPUT, getTempFile());
                        startActivityForResult(intent, SELECT_PICTURE);
 }

            });
            final AlertDialog alert = builder.create();
            alert.show();
  }

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

        switch(requestCode)
        {
case SELECT_PICTURE : if (resultCode == RESULT_OK) 
            {
                  filepath = muri.getPath();
                  Toast.makeText(this, filepath, Toast.LENGTH_SHORT).show();
                //can do bla bla bla...
            }

I have used the same approach and it woks.Hope It could help u too..

1
  • 1
    This is not answering my question. You are downloading the file locally, under /MyFiles, with a timestamp in the file name but are not retrieving any picasa identification information. I do not want to download the file locally, I just need the picasa url of the corresponding file, so I can store it and use it later. This needs to work when the user is offline, so for testing purposes, in airplane mode.
    – oviroa
    Aug 16, 2011 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.