1
00:00:00,330 --> 00:00:04,320
In this tutorial we're going to go ahead and we are going to add another functionality.

2
00:00:04,320 --> 00:00:09,450
Actually it is going to be the final functionality of this application not the final but our application

3
00:00:09,450 --> 00:00:10,640
is almost finished.

4
00:00:10,980 --> 00:00:18,240
So we want to allow the user to share this image with other applications that are going to be that can

5
00:00:18,270 --> 00:00:25,580
interact with other people such as email G-mail telegram app for example or whatsapp or any other applications.

6
00:00:25,830 --> 00:00:27,780
So first we need a button.

7
00:00:27,780 --> 00:00:34,160
So first of all make sure to open the activity under minute example here inside this pallet section

8
00:00:34,170 --> 00:00:40,320
just click on and select this button and just drag it here into our layout and below these six bars

9
00:00:40,320 --> 00:00:40,550
here.

10
00:00:40,560 --> 00:00:46,870
Just put it here so you can see that these constraints are already created for the spot and automatically.

11
00:00:46,920 --> 00:00:48,420
So I want this.

12
00:00:48,530 --> 00:00:52,260
Let's actually select this spot and we need to have a top constraint here.

13
00:00:52,410 --> 00:00:59,130
So if we hover over the top actually edge of the spot and you can see this little circle that is pulsating

14
00:00:59,130 --> 00:00:59,630
right.

15
00:01:00,090 --> 00:01:06,970
I just need to create a constraint to the bottom edge of this actually see each part here of these Baluchi.

16
00:01:06,990 --> 00:01:07,960
But here right.

17
00:01:08,070 --> 00:01:12,450
Just create this constraint here to this little circle and then just release it.

18
00:01:12,720 --> 00:01:18,030
Let's increase the margin top of this spot and so just that it's an expansion inside this property section

19
00:01:18,430 --> 00:01:20,380
for that margin tightest they've been here.

20
00:01:20,490 --> 00:01:23,060
So this is our partner right now.

21
00:01:23,190 --> 00:01:28,500
Let's select the spot and let's provide an item for this spot in between share and then person and to

22
00:01:28,680 --> 00:01:29,600
your keyboard.

23
00:01:29,790 --> 00:01:32,480
And for the text attribute just type in here.

24
00:01:32,610 --> 00:01:36,610
Share your image your image.

25
00:01:37,020 --> 00:01:40,110
Exclamation mark and then personated on your keyboard.

26
00:01:40,230 --> 00:01:40,710
So that's it.

27
00:01:40,710 --> 00:01:42,150
This is our button.

28
00:01:42,600 --> 00:01:49,260
So let's go to our main activity class here let's scroll to the top of the file and first we need to

29
00:01:49,440 --> 00:01:52,340
actually declare our object are valuable.

30
00:01:52,470 --> 00:02:02,530
So private button private button PTEN and share semicolon Let's go to the uncreate effect I here let's

31
00:02:02,710 --> 00:02:08,350
initialize our pity and share buttons so between and share assignment operator let's cast this object

32
00:02:08,350 --> 00:02:11,010
to a button object find view ID.

33
00:02:11,050 --> 00:02:12,680
Our thoughts ideas thoughts.

34
00:02:12,680 --> 00:02:14,760
Pythian shared semicolon.

35
00:02:15,070 --> 00:02:17,760
Now let's pro-white a listener for this one.

36
00:02:17,770 --> 00:02:22,680
So after this line of code that sets the listener for this beauty and save the picture I can see Pythian

37
00:02:22,830 --> 00:02:26,060
share that sets of Kleek listener.

38
00:02:26,080 --> 00:02:31,030
And then here I just need to pass the context the main activity that is because this class main activity

39
00:02:31,030 --> 00:02:34,510
is actually implementing this view that non-clinical is an interface.

40
00:02:34,690 --> 00:02:36,950
You can see that we have no errors here.

41
00:02:37,030 --> 00:02:40,330
So let's find the uncle whomever this is going to be executed and about this.

42
00:02:40,330 --> 00:02:46,810
So we already checked for this condition that if the ID is for example PTEN take a picture if the ID

43
00:02:46,810 --> 00:02:53,530
is BT and say picture and now we need to check for another ID so we can see it adding curly brace of

44
00:02:53,530 --> 00:02:58,960
this LCF statement here that checks whether the ID is actually the BT and save the picture right after

45
00:02:58,960 --> 00:03:05,500
the athing curly brace of this statement I can't create another LCS they've been so LCF actually view

46
00:03:06,850 --> 00:03:13,170
that gets ID is equal to or that ID that Pythian share.

47
00:03:13,180 --> 00:03:19,540
This means that if the user is actually interacting with that BT and shell button inside our user interface

48
00:03:20,050 --> 00:03:23,440
and if the user is pressing this button then its going to execute.

49
00:03:23,440 --> 00:03:25,480
Is this LCP statement here.

50
00:03:25,540 --> 00:03:29,200
So lets go inside these LCF statement and lets see what we are going to do next.

51
00:03:29,200 --> 00:03:30,230
RJ I already won.

52
00:03:30,400 --> 00:03:37,840
So now first let me tell you that sharing an image with other applications can be error prone so we

53
00:03:37,840 --> 00:03:42,180
must put our coats inside a try catch block.

54
00:03:42,430 --> 00:03:42,830
OK.

55
00:03:43,000 --> 00:03:48,360
So let's actually just step in here try and then here after the curly brace of destroyed like just typing

56
00:03:48,440 --> 00:03:54,370
head catch inside the apprentice's just you know to specify the exception so just typing here exception

57
00:03:55,450 --> 00:04:01,600
just open and close this test by using the curly braces and just they've been hit eat that print stacks

58
00:04:01,610 --> 00:04:02,530
race.

59
00:04:02,560 --> 00:04:04,190
So let's go inside is Charlie Black.

60
00:04:04,210 --> 00:04:08,360
First of all we need to create a variable of type file.

61
00:04:08,360 --> 00:04:10,030
You need to have the image file.

62
00:04:10,150 --> 00:04:16,120
So I can just they've been filed and the name of this variable is going to be my picture my picture

63
00:04:16,120 --> 00:04:16,690
file.

64
00:04:16,830 --> 00:04:17,370
Right.

65
00:04:17,410 --> 00:04:23,680
Assignment operator and now I'm going to the first with is safe file class that safelight.

66
00:04:23,770 --> 00:04:28,630
So you know that this save file method is going to return an object of a fight.

67
00:04:28,630 --> 00:04:29,870
Let me show you this method.

68
00:04:29,890 --> 00:04:33,310
Inside the safe class you can see this method here right.

69
00:04:33,310 --> 00:04:37,410
This is actually a static method that the return type of this if it is filed.

70
00:04:37,420 --> 00:04:42,610
So this means this method must return a value of that object so let's go back to main If the class.

71
00:04:42,610 --> 00:04:47,230
So say fine that's a fine here we need to pass two arguments the first one is the activity it's just

72
00:04:47,230 --> 00:04:52,090
they can hear main activity that this and when it is specified is such an argument which is going to

73
00:04:52,090 --> 00:04:54,820
be that bitmap so bitmap semicolon.

74
00:04:54,940 --> 00:04:57,390
Right now this variable might be fine.

75
00:04:57,470 --> 00:05:03,010
File Holts that image the actual image that is saved in Access not storage.

76
00:05:03,370 --> 00:05:09,550
Now I can say so here let me tell you that the reason that we put on this try catch blocks here is that

77
00:05:09,970 --> 00:05:12,800
we wanted to use this method save a file method.

78
00:05:12,810 --> 00:05:13,110
OK.

79
00:05:13,120 --> 00:05:18,460
Because the safe find if it is actually error prone if you must put this code here so that when we want

80
00:05:18,460 --> 00:05:22,960
to share this image with other applications we have no errors there.

81
00:05:22,990 --> 00:05:29,060
So after this line of code we need to create a value but of that you are inside the android that net

82
00:05:29,080 --> 00:05:29,700
package.

83
00:05:29,710 --> 00:05:31,800
Ok not Java dot net but this one.

84
00:05:31,810 --> 00:05:33,380
And that's not you or I.

85
00:05:33,430 --> 00:05:36,770
And the name of this variable is going to be my you or I.

86
00:05:36,790 --> 00:05:43,480
Assignment operator so I mean if you have this you are here in order to access our saved a picture file.

87
00:05:43,600 --> 00:05:49,170
So I can just say you are I thought fit on file from file.

88
00:05:49,290 --> 00:05:53,480
And now we just need to pass my picture file here semi-colon.

89
00:05:53,620 --> 00:05:57,210
That's it because we want to share our image with other applications.

90
00:05:57,220 --> 00:06:00,190
We need to create a new intent called sheer intent.

91
00:06:00,190 --> 00:06:01,770
Let's just say be here intent.

92
00:06:01,840 --> 00:06:03,930
The name of this intent is going to be shared.

93
00:06:03,930 --> 00:06:07,030
Intent assignment operator new intent.

94
00:06:07,150 --> 00:06:13,220
And inside the Apprentice it's just they've been here intent that action sent intent that action sent.

95
00:06:13,240 --> 00:06:14,810
Let's actually find it here.

96
00:06:14,870 --> 00:06:20,410
And so this is our intent that we want to open the action center it's going to allow us this intent.

97
00:06:20,410 --> 00:06:27,400
And I was to choose the applications that we share our image with other users such as whatsapp email

98
00:06:27,400 --> 00:06:31,160
Gmail or any other applications that you have installed on your device.

99
00:06:31,280 --> 00:06:35,060
And now if you need a specific data type this is the type of the intent.

100
00:06:35,080 --> 00:06:36,240
So it's a step in here.

101
00:06:36,250 --> 00:06:43,240
Sure intent that set type to just put two coats here this type is very case sensitive it must be lower

102
00:06:43,240 --> 00:06:43,630
case.

103
00:06:43,660 --> 00:06:54,040
So just typing here text slash plane semi-colon OK the type must be text slash playing because we want

104
00:06:54,040 --> 00:06:59,160
to share this actually find with other applications for the time step in here.

105
00:06:59,260 --> 00:07:03,850
TEXT slash play a plain text right now even to specify the text.

106
00:07:03,850 --> 00:07:11,620
So in other words we want to specify the subject of the image so I can say Shirlington that put extra

107
00:07:12,130 --> 00:07:13,850
here just typing here put extra.

108
00:07:13,870 --> 00:07:20,110
So we need to specify the type the type is going to be subject right intense that extra subject intent.

109
00:07:20,110 --> 00:07:24,720
Let me just type in intent that extra subject.

110
00:07:24,730 --> 00:07:28,870
Ok comma and now we need to specify the actual text.

111
00:07:28,930 --> 00:07:31,270
So just put two coats and just type in here.

112
00:07:31,270 --> 00:07:33,440
This picture is sent.

113
00:07:33,460 --> 00:07:40,720
This picture is sent from color app that I created myself that I created myself for example right.

114
00:07:40,770 --> 00:07:41,510
Semicolon.

115
00:07:41,770 --> 00:07:42,190
OK.

116
00:07:42,250 --> 00:07:46,630
You can actually use this application in order to send images to your friends.

117
00:07:46,960 --> 00:07:49,570
And this message is going to be shown to the users.

118
00:07:49,570 --> 00:07:53,210
Ok this picture is sent from the color app that I created myself.

119
00:07:53,470 --> 00:07:54,560
Now I can say.

120
00:07:54,610 --> 00:07:56,390
So we need to pass.

121
00:07:56,410 --> 00:07:59,770
We need to actually send the 5 the picture file with you.

122
00:07:59,840 --> 00:08:00,460
Right.

123
00:08:00,490 --> 00:08:02,040
So I can say sharing Sherrington.

124
00:08:02,080 --> 00:08:10,600
That puts extra intent that extra steam stream actually to intent that extra stream.

125
00:08:10,660 --> 00:08:11,570
Is this fun.

126
00:08:11,580 --> 00:08:15,270
Karma and that we can pass that you are a my you are right.

127
00:08:15,600 --> 00:08:18,170
Semicolon if you don't put this line of code here.

128
00:08:18,340 --> 00:08:23,610
The app is not going to be able to actually send the picture file the picture with the intent.

129
00:08:23,680 --> 00:08:26,560
The other use to add X actually the to other users.

130
00:08:26,560 --> 00:08:32,130
So it is very important and it's that threat stream need to pass this here as a threat stream.

131
00:08:32,230 --> 00:08:36,010
And in my you or I here in other words it is actually a map right.

132
00:08:36,010 --> 00:08:42,410
Key value x threat stream is the key and the you is the value which has my picture file.

133
00:08:42,430 --> 00:08:45,720
Here in line number one hundred and forty you can see this my picture file.

134
00:08:46,090 --> 00:08:51,640
So when you say X threat stream this means that we want to actually send a file.

135
00:08:51,900 --> 00:08:52,410
OK.

136
00:08:52,420 --> 00:08:56,830
With this intent and that file is going to be my you are right that holds this might be terrified.

137
00:08:56,920 --> 00:09:02,130
In other words not actually holds but has a reference to this my picture file.

138
00:09:02,170 --> 00:09:09,340
So now I can say start activity intent that create chooses so you can actually open an intent for us

139
00:09:09,340 --> 00:09:14,800
in order to choose the applications that we want to actually share the image with.

140
00:09:14,800 --> 00:09:19,160
First we need to pass we can see that use to create chooser here.

141
00:09:19,430 --> 00:09:22,290
Not now we need to pass the intent that we created here.

142
00:09:22,300 --> 00:09:26,740
So the intent is going to be sharing karma and then we need to pass the message.

143
00:09:26,740 --> 00:09:34,000
So I just put two coats here and here I can say let's share your image your picture actually your picture.

144
00:09:34,010 --> 00:09:41,300
The other apps with others here let me create some new lines so that you can see these values better.

145
00:09:41,310 --> 00:09:43,790
So let's share your picture with others.

146
00:09:44,040 --> 00:09:49,280
So these are the codes that we need in order to share in order to allow the app to share our image a

147
00:09:49,280 --> 00:09:50,640
picture of it.

148
00:09:50,670 --> 00:09:52,130
Other applications.

149
00:09:52,200 --> 00:09:59,070
So now it's time to run the application but under the emulator it's not going to work properly.

150
00:09:59,070 --> 00:10:05,580
If you want to actually see it work properly make sure to test your app on your actual device device.

151
00:10:05,580 --> 00:10:08,870
So for now I just want to show you how it works on the emulator.

152
00:10:09,330 --> 00:10:11,550
Let me show you the emulator now.

153
00:10:11,630 --> 00:10:13,530
Our Are is running on the simulator.

154
00:10:13,530 --> 00:10:15,440
Let's take a picture with this one.

155
00:10:15,570 --> 00:10:18,640
And then here let's click on share your image.

156
00:10:18,670 --> 00:10:22,260
When I click on your image it connects you to say cell select conversation.

157
00:10:22,370 --> 00:10:25,950
Well once you start in your conversation you'll see that here.

158
00:10:26,100 --> 00:10:31,650
So the only app that is on the emulator that is actually available in order to share our image with

159
00:10:31,650 --> 00:10:33,070
is the message.

160
00:10:33,150 --> 00:10:36,800
Let's click on your message and open them message up here for us.

161
00:10:36,840 --> 00:10:43,460
So if you want to actually see other applications make sure to test this app on your actual device where

162
00:10:43,470 --> 00:10:48,690
you have lots of other messaging applications for example such as a whatsapp or any other messaging

163
00:10:48,690 --> 00:10:52,590
applications that you can share your image with others.

164
00:10:52,590 --> 00:10:53,850
So that's it.

165
00:10:54,060 --> 00:11:00,720
But we need to add the final functionality to this application and that that is the DS subparts I want

166
00:11:00,720 --> 00:11:04,080
this search bar here to display this form.

167
00:11:04,090 --> 00:11:05,050
Actually look at this one.

168
00:11:05,070 --> 00:11:11,310
I want this one to be read and I want the form of this sequel to be clean and I want the form of the

169
00:11:11,310 --> 00:11:13,480
search bar to be actually blue.

170
00:11:13,500 --> 00:11:17,280
I'm going to add that functionality in the next story or if you have any questions about the concepts

171
00:11:17,280 --> 00:11:21,210
that they taught you in this lesson please post the discussion in the course and then I do my best to

172
00:11:21,210 --> 00:11:22,490
answer all of your questions.

