Tell me how to implement a mechanism for downloading images, for example, from a gallery into your application and how to handle them in the application. At least ideologically tell me, and then I pick up.
- Depending on what functionality is needed. there are different libraries, for example, Glide - tim_taller
- you just need to upload pictures to the application, then show them there - Dimantik02
- github.com/nostra13/Android-Universal-Image-Loader look at the library, there are examples, I think you will immediately understand everything - Maxim Kuznetsov
|
1 answer
Can be done through intent:
Launch an activity with Intent ACTION_PICK to upload a picture from the standard Android gallery, for this we create an Intent :
Intent i = new Intent(Intent.ACTION_PICK); i.setType("image/*"); startActivityForResult(i, REQUEST); When creating an Intent, we pass the ACTION_PICK constant to show that we need to select some данные.i.setType("image/*") - and here we specify the type of data we want to receive. onActivityResult we implement the onActivityResult method:
protected void onActivityResult(int requestCode, int resultCode, Intent data){ Bitmap img = null; if (requestCode == REQUEST && resultCode == RESULT_OK) { Uri selectedImage = data.getData(); try { img = Media.getBitmap(getContentResolver(), selectedImage); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } super.onActivityResult(requestCode, resultCode, data); } We have img with which we are already working as usual Bitmap .
- Well, the style of the code ( - Artem Shevchenko
|