You need to take the url pictures from the gallery and save the link to the database so that you can open it later. I saved the link, but the file will not open.

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) { Uri uri = data.getData(); try { Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri); imageView = (ImageView) findViewById(R.id.image); imageView.setImageBitmap(bitmap); uriImg = uri.toString(); } catch (IOException e) { e.printStackTrace(); } } } 

I try to open, but nothing happens.

  File imgFile = new File(uriImg); if (imgFile.getAbsoluteFile().exists()){ Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); imageView.setImageBitmap(myBitmap); 
  • The sylink looks like this content://media/external/images/media/64 - Bogdan Shulga
  • Are there any permissions for writing / reading files from a device in the manifest? .. - YuriiSPb
  • It's strange that the picture does not have an extension - Android Android
  • <uses-permission android: name = "android.permission.WRITE_EXTERNAL_STORAGE"> </ uses-permission> this is in the manifest - Bogdan Shulga
  • Yes it saves the link without extension, but I tried to add .jpg in the manual folder. No result - Bogdan Shulga

2 answers 2

Give write and read access to AndroidManifest.xml and try this:

 if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) { Uri uri = data.getData(); imageView.setImageURI(uri); } 
  • The problem is not that the picture does not open at all. And the fact that the link which is saved to the file looks like some kind of nonsense. content://media/external/images/media/64 - Bogdan Shulga

This construction returns the image url of a picture: All thanks for the feedback.

  String uriImg; Uri uri = data.getData(); Cursor cursor = null; try { String[] proj = {MediaStore.Images.Media.DATA}; cursor = getApplication().getContentResolver().query(uri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); uriImg = cursor.getString(column_index); } finally { if (cursor != null) { cursor.close(); } }