‫Let's get the image from the gallery.
‫Display a thumbnail in the image view and prepare it for uploading to the Firebase store.
‫For that, I'll use a new way in Android called Activity Result.
‫Launcher.
‫Since start activity for result is deprecated.
‫I'll start by initializing David result launcher passing string as its type parameter and name it as
‫take photo.
‫Let's initialize this and talk about it.
‫Again guys, we use this method for picking using the activity result.
‫Launcher and the register for activity result method.
‫Here to pick a content from the user's device, such as an image or files.
‫This feature is part of the Android X activity result library introduced to simplify working with activity
‫results.
‫Let's explain more.
‫Register for activity result.
‫This is a method used to register an activity result callback.
‫It allows you to specify an activity result contract, a predefined contract, or a custom one that
‫describes the type of activity result you want to handle and how to handle it.
‫And here we need to pass a parameter of type contract.
‫So you can see we need to pass new activity result contracts dot get content.
‫Get content is one of the predefined activity result contracts provided by Android X activity result.
‫It's used for opening a file picker or gallery picker to select content such as images or files from
‫the device.
‫This contract simplifies the process of getting content from the user, and here we need to pass another
‫parameter.
‫Activity result callback and we need to override on activity result method.
‫Here we need to handle the selected content.
‫You are I.
‫So for example you can display an image from the Uri.
‫So for that I'll use image view dot set image resource or image uri.
‫This result.
‫And that's it.
‫We need to display the image.
‫And here add photo button set on click listener.
‫We need to get the image from the gallery.
‫And we need to specify what type of files we need to get.
‫So for that I need to use take photo dot launch.
‫The input should be of type image all types of images.
‫This is an argument that specifies that we want to pick image files.
‫You can change it to other Mime types based on your requirements, for example PDF videos, mp4 and
‫others.
‫But in this application we are interested in the images files.
‫I'll create this method in the add journal activity in order to allow me to run this application and
‫test.
‫So to detect the add journal activity, I need to go to the activity Underscore join list.
‫And I'll create a fab here in order to allow the user to create a new journal list.
‫Wrap content wrap content id fab.
‫And this.
‫Hello green light.
‫It's good.
‫You can get this code 99 cc zero zero and replace it.
‫For example, I'll drag and drop this fab to here and infer the constraints 16 from the button and 16
‫from the right.
‫Let's move to the add Journal activity.
‫Scroll up and here in the widgets section I'll create private fab floating action button.
‫I'll initialize it here.
‫Oops.
‫I added this at the journal, so I need to go to the journal list activity and I need to add it here.
‫And remove it from a journal.
‫Go to journal list and initialize it.
‫Then I need to add a click listener to the to this fab.
‫And direct the user from the journal list activity.
‫Do this to them at journal activity dot class start activity.
‫This fab in order to direct the user from the journal list activity to the add journal activity run.
‫Sign in.
‫And this is the fab here.
‫Click on it and this is our activity.
‫Click on this icon.
‫And this is our gallery download.
‫And I select this photo.
‫And here we go.
‫You can see it.
‫This is our photo.
‫We need to add other fields in order to be able to upload it to the Firebase Firestore.
‫But for now we're good.
‫We learned how to get an image from the gallery.