Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the images from device in android java application

Tags:

android

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?

like image 330
Aswan Avatar asked Feb 09 '10 06:02

Aswan


People also ask

How do I access my gallery on Android?

On your Android phone, open Gallery . New folder. Enter the name of your new folder. Choose where you want your folder.

How do I import images into Android Studio?

To import image resources into your project, do the following: Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import.

What is Android ImageView?

ImageView class is used to display any kind of image resource in the android application either it can be android. graphics. Bitmap or android. graphics. drawable.


1 Answers

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);
        }
}
like image 81
Samuh Avatar answered Oct 19 '22 17:10

Samuh