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

  • What exactly is the problem? You do not know how to create a database, how to put a record in the database, how to read from the database, how to determine the download from the database or from the gallery, another? What has already been done by yourself that does not work. In the current form, your question is too general and requires solving several problems, while there should be only one problem in the question. The code in question does not relate to the problem (there are no attempts to work with the database) - pavlofff
  • The database is ready and I know how to work with it, I do not know how to convert Uri to a record to put into a database, and then how to create a Uri - Dimantik021 from the record

1 answer 1

To write Uri to the database, it is necessary to convert it to a string, and save the string to the database.

 Uri uri; String stringUri; stringUri = uri.toString(); 

For the inverse transform, get a string from the database and convert it to Uri :

 Uri uri; String stringUri; uri = Uri.parse(stringUri); 
  • I did exactly as you said. If anything, I get Uri on a photo from the gallery. But when I try to upload a photo by Uri, the catch block is triggered, with these lines I'm trying to get a photo - Dimantik021
  • Bitmap bitmap = MediaStore.Images.Media.getBitmap (getActivity (). GetContentResolver (), uri); mPhotoCard.setImageBitmap (bitmap); - Dimantik021