检索的Picasa图片从画廊上传画廊、上传、图片、Picasa

2023-09-04 03:02:37 作者:ωǒ┑对不屑

我工作的一个活动,并允许用户选择图像从画廊的个人资料图片使用的相关任务。一旦作出选择的图像被上传到经由其API的Web服务器。我有这个工作经常图像从画廊。然而,如果所选择的图像是从的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的图片返回一个空指针。 MediaStore.Images.Media.DATA 是没有的为他们空,但是。它只返回一个#ID,所以我猜测,有在该地址没有任何实际的位图数据。本地存储设备上的所有Picasa的图片吗?

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?

我还注意到从 MediaStore.Images.ImageColumns.PICASA_ID 存在的文档。此值存在选择的Picasa的图片,但没有其他的画廊图像。我想我可以用这个值来获得一个网址的形象,如果它没有本地存储,但我无法找到它的任何地方的任何信息。

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.

推荐答案

我曾经面临相同问题, 最后,我找到了解决办法,就是发动ACTION_PICK的ACTION_GET_CONTENT意图,而不是,那么请确保您提供MediaStore.EXTRA_OUTPUT额外的与URI到一个临时文件。 这里是code键启动意图:

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);
    }

    (...)
}

您可能需要mTempFile.createFile()

You might need to mTempFile.createFile()

然后,在onActivityResult,你将能够获得图像这样

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).

 
精彩推荐