Good day.
How can I, by pressing a button, call up a gallery of a smartphone, can I select an image and use it as a button background and not only?
I decided:
Using Intent.ACTION_PICK and Uri solved my problem
static final int GALLERY_REQUEST = 1; imageButton = (Button) rootView.findViewById(R.id.add_image); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, GALLERY_REQUEST); } }); ... @Override public void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); switch (requestCode) { case GALLERY_REQUEST: if (resultCode == RESULT_OK) { try { final Uri imageUri = imageReturnedIntent.getData(); final InputStream imageStream = getActivity().getContentResolver().openInputStream(imageUri); final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream); Drawable d = new BitmapDrawable(getResources(), selectedImage); imageButton.setBackground(d); } catch (FileNotFoundException e) { e.printStackTrace(); } } } } 
