在我的应用程序,我要上传的图片。
In my application I want to upload the image.
有关,我必须得在Android设备从画廊的图片。
For that I have to get images from gallery in android device.
我怎样写code,完成此?
How do I write code that accomplishes this?
提起的意图与行动为 ACTION_GET_CONTENT
和类型设置为图像/ *
。这将启动照片选择器活动。当用户选择一个图像,您可以使用 onActivityResult
回调得到的结果。
Raise an Intent with Action as ACTION_GET_CONTENT
and set the type to "image/*
". This will start the photo picker Activity. When the user selects an image, you can use the onActivityResult
callback to get the results.
是这样的:
Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK)
{
Uri chosenImageUri = data.getData();
Bitmap mBitmap = null;
mBitmap = Media.getBitmap(this.getContentResolver(), chosenImageUri);
}
}