I upload photos from the gallery in this way
mDownloadPhoto.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, GALLERY_REQUEST); } }); Then
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_PHOTO){ updatePhoto(); Toast.makeText(getContext(), "r", Toast.LENGTH_SHORT).show(); } else if (requestCode == GALLERY_REQUEST) { if (resultCode == Activity.RESULT_OK){ Uri selectedImage = data.getData(); setImageBitmapFromUri(selectedImage); } } } private void setImageBitmapFromUri(Uri uri){ try { Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), uri); ImageView.ScaleType scaleType = ImageView.ScaleType.CENTER; mPhotoCard.setScaleType(scaleType); mPhotoCard.setImageBitmap(bitmap); mCard.setPhotoName(uri.getScheme()); mCardLab.updateCard(mCard); Toast.makeText(getContext(), uri.getScheme(), Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); } } How to put the Uri into the database so that on the next launch, the program loads the image automatically, extracting the uri from the database