Upload Picasa Image to Download from Gallery

I work on tasks and related tasks that allow users to select an image to use as a profile image from the Gallery. After the choice is made, the image is uploaded to the web server through its API. I have regular images from the gallery. However, if the selected image is selected from Picasa Web Album , nothing is returned.

I did 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. It returns only #id, so I assume that there is no actual bitmap data at the address. Are Picasa images stored locally on the device?

I also noticed from the documentation that there is MediaStore.Images.ImageColumns.PICASA_ID . This value exists for selected picasa images, but not for other gallery images. I thought I could use this value to get the URL for the image if it is not local storage, but I cannot find any information about it anywhere.

+13
android picasa
May 10 '11 at 1:34
source share
2 answers

I ran into the same problem
Finally, the solution I found was to run ACTION_GET_CONTENT, not ACTION_PICK, and then make sure that you provide MediaStore.EXTRA_OUTPUT additionally with uri to the 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 may need mTempFile.createFile ()

Then in onActivityResult you can 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 at the end (it is in the internal storage as it is, but you can use external storage, I think it would be better).

+5
May 12 '11 at 12:43
source share

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

If you want to convert a Uri object 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; } 
+1
Oct 11 '12 at 8:12
source share



All Articles