Importing images from Google to the Android app

Asked

Viewed 61 times

1

I’m building an App in which I want it to allow, through a button, I choose images from the gallery and include and save inside the application. But I have a problem IMAGE_GALLERY_REQUEST because Netbeans says it can’t find the symbol. I’m kind of a layman on the subject so I ask you to be as clear as possible in your reply. Thank you.

    public void onImageGalleryClicked(View v) { 

    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
    File pictureDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    String pictureDirectoryPath = pictureDirectory.getPath();
    Uri data = Uri.parse(pictureDirectoryPath); 
    photoPickerIntent.setDataAndType(data, "image/*"); 
    starActivityForResult(photoPickerIntent, IMAGE_GALLERY_REQUEST); 

}

1 answer

3


The second parameter of the method startActivityForResult() is an integer to identify this "request".

startActivityForResult() is used in conjunction with the method onActivityResult() which will be called after the launched Activity is finished.

How can you only have one onActivityResult() in each Activity, this identifier is used to know which was the startActivityForResult() who called him.

Alter

starActivityForResult(photoPickerIntent, IMAGE_GALLERY_REQUEST); 

for

starActivityForResult(photoPickerIntent, 1); 

or declare the constant IMAGE_GALLERY_REQUEST:

protected final static int IMAGE_GALLERY_REQUEST = 1;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.