我如何从库中检索图像的Picasa ID / URL [英] How do I retrieve the Picasa id/URL of an image from the gallery
问题描述
我有获取从设备的画廊图像,并上传到服务的活动。现在,优化的目的,我想避免上传是在Picasa中只存储它们的ID或URL供以后检索图像。
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.
所以我的问题是,我怎么检索该信息。我的意图code粘贴下面并检索图像的URI。
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);
我试着去找PICASA_ID(MediaStore.Images.Media.PICASA_ID),但通过使用上述方法,则返回null。任何想法?
I tried to look for the PICASA_ID (MediaStore.Images.Media.PICASA_ID), but by using the method above, it returns null. Any ideas?
推荐答案
-
启动一个
ACTION_GET_CONTENT
的意图,而不是一个ACTION_PICK
提供一个 MediaStore.EXTRA_OUTPUT
额外与 URI
到一个临时文件。
Provide a MediaStore.EXTRA_OUTPUT
extra with an URI
to a temporary file.
添加到您的的调用活动的
Add this to your calling activity:
File yourFile;
现在使用的的 code获得意图的
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);
确保 yourFile
创建
另外,在您的的调用活动的
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;
}
这篇关于我如何从库中检索图像的Picasa ID / URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!