Tell me how to implement the picture selection dialog to upload it further to the server? I use okhttp as a library for network interaction.

Closed due to the fact that the essence of the issue is incomprehensible to the participants insolor , rjhdby , dirkgntly , Kromster , Kirill Stoianov October 9 '16 at 17:31 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • what do you need? - help in creating a dialogue? or how to send pictures to the server? More specifically - Flippy

1 answer 1

Declare method:

private void pickImage() { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, REQUEST_CODE_GALLERY_FILES); } 

Optionally, declare another method (which returns the full Uri path):

 private String getRealPathFromURI(Uri contentUri) { String[] proj = { MediaStore.Images.Media.DATA }; CursorLoader loader = new CursorLoader(getApplicationContext(), contentUri, proj, null, null, null); Cursor cursor = loader.loadInBackground(); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); String result = cursor.getString(column_index); cursor.close(); return result; } 

Next, override onActivityResult(...) :

 @Override protected void onActivityResult(int requestCode, int resultCode, Intent returnedIntent) { super.onActivityResult(requestCode, resultCode, returnedIntent); if (returnedIntent == null) return; switch (requestCode) { case REQUEST_CODE_GALLERY_FILES: Uri uri = returnedIntent.getData(); String path = getRealPathFromURI(uri); break; } } 

As a result, in the path get the path to the picture.