android select image from gallery intent When I click the button it would redirect to gallery and I would be able to select an image. The selected image would appear in my ImageView.
Intent intent = new Intent(Intent.ACTION_PICK); intent.setType("image/*"); getActivity().startActivityForResult(intent, REQUEST_CODE); protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == REQUEST_CODE) { Uri ImageUri = data.getData(); if (ImageUri != null) { String ImagePath = getRealPath(ImageUri); profileFragment.uploadImage(ImagePath); } } } if (resultCode == RESULT_CANCELED) { // Write your code if there's no result } }
No comments:
Post a Comment