Welcome back.
Now let's finalize this up and therefore we need to add a little feature which will allow us to export
to image or share the image with our friends with different applications, which allow that, for example,
if you have WhatsApp installed, then you could share your image with WhatsApp.
OK, so let's go ahead and see how we can do that.
Therefore, what we will need to do is we need to go to the point where we actually want to share something
and that will happen in our unposed execute.
Because only as soon as the image is ready, we will be able to share it.
So we need to go to our, I think, class.
I think it has class here at the very bottom bitmap async task.
And then we have this unposed execute.
And after all of that is done, that's where we can go ahead and share the file.
And in order to do so, we can use media scanner connection.
So there's a class called Media Scanner Connection.
And then we can call it scan file method here.
We need to pass in the context and here I will use this at main activity.
As I told you earlier, we cannot just use this here because we are not inside of the context of the
main activity, but we are in the side of the context of our async class or async task class.
And then we need to pass on the result array of result and the mime types, which we can just get to
know.
All right.
So if you want to know more about this scan file method, you can, of course, check up the documentation.
You can see that there are multiple different parameters, mind types, for example, optional array
of mind types for each path and so forth.
So convenience for constructing a media scanner, connection, calling, connect on it and calling scan
file with a given path and the mind type when the connection is established.
OK, so let's just go ahead and run some code in here.
So instead of the scan file, we have another lambda expression.
So we have a path and the URAI has the parameters.
And then what shall be executed?
Well, value, share intent is going to be an intent that I'm going to create because as we saw earlier,
when you want to open something up, then you need to create an intent for that.
OK, so let's use the share intent.
And run an action on it and the action that I want to start is intent, that action sent.
And as you can see, there are so many different actions that you can use here.
Action, better law, action, a better OK or better.
OK, and so forth.
And I want to run the action underscore sent.
Now, the next thing we need to add to this shared intent is to give him some additional information.
And you can do that by using the put extra and you can see here you have a name and a value.
So this is something that is like a map where you have a name and the value assigned to it, but only
one entry.
So we put something extra to this intent.
So we had information which then can be read later on.
So the string that I want to pass and what a name, so to speak, is going to be the intent.
That extra stream and the value that I want to person is going to be my urai.
So this you arrive here.
That I get from my skin file.
So what's happening here is that I have a content, your I holding a stream of data associated with
the Internet, used to supply the data being sent, and then I can go ahead and use to share content
and give it a type.
So I need to say of what type that should be.
And it should be of type image.
And then I can start the activity because I prepared the intent, so these are the additional information
that I need to pass to it and I can start activity.
And here, intent that create chooser.
And in here has the target intent and the target intent is Mushir intent, which I prepared, and then
the title, which I'm going to call Shia.
And by the way, this type here is the MYM type of the data being handled by this intent.
So now what it will do is it will this plan activity Tuzer allowing the user to pick what they want
before proceeding?
This can be used as an alternative to the standard activity picture that you have and that is displayed
by the system when you try to start an activity with multiple possible matches.
So let's have a look at what that means and practice.
So we have pretty much just set up this code here, and this code itself will already be enough in order
to share something with our friends so that the functionality behind it is baked into Android so we
can just use it.
So let's see.
Let's draw something nice here.
Very beautiful, and now.
You can see it saved it and then this share window popped up, that share not available, so no one
is close by or nearby.
But then you can see there is a whole list with which I could share it so I could share to Google Drive
to email and so forth.
So now you can, of course, go ahead and send it via Gmail, but then you would have to log into a
Gmail account and then, yeah, pretty much only then we would be able to do that.
All right.
So that is it.
Of course, this application is not fully done yet.
You could, of course, improve it.
And so many levels, you could add a random color, as I said earlier.
So this color is called random, but it's not really a random color.
So you could make it random or you could add a color picker here, which allows you to select pretty
much any color there is.
Then you could get rid of this HEPA here at the top if you want to have more real estate to draw.
You could have a slider in order to select a size that you want to use.
So in our case, we just use three sizes.
But you could have just this ladder, which has a bunch of different options.
You could have a redo button.
So not just an undue button, but a redo button, which brings the last thing that you take for the
last stroke that you deleted back into the application.
And of course, you could add a bunch of different effects, such as blur effects or color effects or
whatever you can think of to make the image even better.
But overall, we have a working up here and you have the working foundation now.
You can, of course, do all of those additional things.
And if you do so, feel free to share it with us.
If you have any thing cool to share with the other students, I would be super happy about that.
And then they can see how it's done.
Or you could just go ahead and optimize the app and improve the app to the point where you can just
share it on the App Store or sell it even on the App Store.
Either way, I wish you good luck with it and I'm super grateful that you're still with me.
Thanks a lot for going that far into the course and really learning how to build all of these apps.
It's really a passion of mine to teach you, and I hope you enjoy the course and go through the next
chapters as well.
So thanks again and see you in the next chapter.