SHARE
TWEET

Untitled

a guest Sep 22nd, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Button btn_choose_photo = getView().findViewById(R.id.importImage);
  2.         btn_choose_photo.setOnClickListener(btnChoosePhotoPressed);
  3.     }
  4.  
  5.     public View.OnClickListener btnChoosePhotoPressed = new View.OnClickListener() {
  6.         @Override
  7.         public void onClick(View v) {
  8.             Intent i = new Intent(Intent.ACTION_PICK,
  9.                     android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
  10.             final int ACTIVITY_SELECT_IMAGE = 1234;
  11.             startActivityForResult(i, ACTIVITY_SELECT_IMAGE);
  12.         }
  13.     };
  14.  
  15.     public void onActivityResult(int requestCode, int resultCode, Intent data) {
  16.         super.onActivityResult(requestCode, resultCode, data);
  17.  
  18.         switch (requestCode) {
  19.             case 1234:
  20.                 if (resultCode == Activity.RESULT_OK) {
  21.                     Uri selectedImage = data.getData();
  22.                     String[] filePathColumn = {MediaStore.Images.Media.DATA};
  23.  
  24.                     Cursor cursor = getContext().getContentResolver().query(selectedImage, filePathColumn, null, null, null);
  25.                     cursor.moveToFirst();
  26.  
  27.                     int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
  28.                     String filePath = cursor.getString(columnIndex);
  29.                     cursor.close();
  30.  
  31.                     yourSelectedImage = BitmapFactory.decodeFile(filePath);
  32.  
  33.                     ImageView mImg;
  34.                     mImg = getView().findViewById(R.id.profile_image);
  35.                     mImg.setImageBitmap(yourSelectedImage);
  36.     }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top