开发者

how to get the images from device in android java application

开发者 https://www.devze.com 2022-12-19 09:37 出处:网络
In my application I want to upload the image. For that I have to get images from gallery in android device.

In my application I want to upload the image.

For that I have to get images from gallery in android device.

How do I write code that accomplishes this?开发者_运维技巧


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.

Something like:

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

精彩评论

暂无评论...
验证码 换一张
取 消