1
00:00:00,290 --> 00:00:08,320
Hire everyone in this tutorial I want to show you how you can download and upload files to firebase.

2
00:00:08,640 --> 00:00:12,020
So let's create a new Android studio project here.

3
00:00:12,060 --> 00:00:18,750
So the application name is going to be upload and download files.

4
00:00:18,750 --> 00:00:23,640
So here you can specify the company domain the partitioning and the project location.

5
00:00:23,640 --> 00:00:30,990
So just going to connect here choose API 16 Android 4.1 jelly bean as the minimum SDK for phone and

6
00:00:30,990 --> 00:00:36,280
tablet on next and here choose empty activity next.

7
00:00:36,570 --> 00:00:37,990
And here don't change anything.

8
00:00:38,010 --> 00:00:39,520
Just click on finish.

9
00:00:39,750 --> 00:00:46,440
So now that a project is created let's actually connect this project to the Firebrace.

10
00:00:46,440 --> 00:00:47,440
So at the top menu.

11
00:00:47,460 --> 00:00:50,840
Just click on Tools and here click on Firebrace.

12
00:00:51,360 --> 00:00:52,660
Let's wait a little bit here.

13
00:00:52,830 --> 00:00:56,160
And now you can see that this assistent area is opened.

14
00:00:56,280 --> 00:01:02,460
Click on storage and here click and upload and download a file with firebase storage.

15
00:01:02,700 --> 00:01:05,490
So here first we need to connect to firebase.

16
00:01:05,490 --> 00:01:08,620
Here you can see that these starts connect dialog opens.

17
00:01:08,670 --> 00:01:13,590
So let's wait a little bit here and here it says create new firebase project.

18
00:01:13,590 --> 00:01:15,420
So this is the name of the project.

19
00:01:15,720 --> 00:01:21,210
And here you can specify the country region and click on Connect to firebase.

20
00:01:21,210 --> 00:01:28,520
So now that the app is connected to firebase now it's time to add firebase storage to our application.

21
00:01:28,710 --> 00:01:32,260
So just click on the spot in here at firebase threshed your app.

22
00:01:32,490 --> 00:01:38,040
And here you can see these changes that will actually take place inside our project.

23
00:01:38,100 --> 00:01:40,080
So just click and accept changes.

24
00:01:40,080 --> 00:01:41,570
So let's wait a little bit here.

25
00:01:41,580 --> 00:01:47,700
Here you can see it's cradle and it's actually doing something some processes are happening here.

26
00:01:47,760 --> 00:01:49,370
So let's wait a little bit here.

27
00:01:49,380 --> 00:01:52,500
So now it says dependences set up correctly.

28
00:01:52,770 --> 00:01:56,730
So let's collapse this assistent area by just clicking on the spot in here.

29
00:01:56,940 --> 00:01:58,860
So this is our project.

30
00:01:58,860 --> 00:02:02,980
Now let's go to our activity Underland minute exam segment here.

31
00:02:03,190 --> 00:02:07,650
And let's actually double click on the stop here in order to make this area of Vider selectees hello

32
00:02:07,650 --> 00:02:11,340
world takes you here and and pre-press on Dorothy on your keyboard.

33
00:02:11,340 --> 00:02:18,870
So here first of all we want to allow the user to upload an image to the actually Firebrace storage.

34
00:02:18,870 --> 00:02:26,220
So here inside this pallet section just click on images here and you can see this image button image

35
00:02:26,220 --> 00:02:27,350
view video view.

36
00:02:27,390 --> 00:02:31,270
So for now we just we don't want to actually work with these objects.

37
00:02:31,410 --> 00:02:37,270
Let's click on all and let's click on this button here select the spot and just track it here into this

38
00:02:37,270 --> 00:02:38,310
constraint to lay out.

39
00:02:38,330 --> 00:02:43,290
Notice that this is a constraint and not a relative or a linearly out.

40
00:02:43,410 --> 00:02:45,300
So just put the button here.

41
00:02:45,300 --> 00:02:49,000
I select spot button let's add the constraint to the top of this view.

42
00:02:49,140 --> 00:02:53,730
So you can see this little circle here on the top edge of this button that is pulsating.

43
00:02:53,730 --> 00:02:57,600
So let's create a constraint to the top of the view here.

44
00:02:57,600 --> 00:03:01,340
So now here inside this property section you can see these constraints.

45
00:03:01,350 --> 00:03:07,260
So for the top constraint Let's actually change this value to number 18 and let's select this button

46
00:03:07,260 --> 00:03:07,980
here.

47
00:03:07,980 --> 00:03:18,400
So for the ticks Let's actually just open here upload upload the image to firebase Firebrace and in

48
00:03:18,400 --> 00:03:20,090
person until you are on your keyboard.

49
00:03:20,170 --> 00:03:23,060
Let's give an idea to the Spartans select disputant.

50
00:03:23,230 --> 00:03:29,510
So for the ideas they've been here PTEN upload image and that person entered January keyboard.

51
00:03:29,530 --> 00:03:34,780
So now let's open our browser here now here inside the search.

52
00:03:34,780 --> 00:03:38,830
Put up your web browser search for Picasso Android.

53
00:03:39,090 --> 00:03:42,100
So we need to add this library to our project.

54
00:03:42,160 --> 00:03:44,900
So here we can see this first link that appears here.

55
00:03:44,980 --> 00:03:46,140
Picasso that square.

56
00:03:46,150 --> 00:03:47,670
Open Source.

57
00:03:47,770 --> 00:03:49,220
Let's click on it.

58
00:03:49,660 --> 00:03:51,030
Let's wait a little bit here.

59
00:03:51,040 --> 00:03:53,000
So now let's scroll down here.

60
00:03:53,020 --> 00:03:58,570
So let's actually take a look at this introduction it says images add a much needed context and visual

61
00:03:58,570 --> 00:04:00,610
flair to Android applications.

62
00:04:00,610 --> 00:04:05,080
Picasa allows for hassle free image loading in your application.

63
00:04:05,170 --> 00:04:12,430
Often in one line of code many common pitfalls of image loading up on Android are handled automatically

64
00:04:12,430 --> 00:04:17,720
by Picasso handling image recycling and download cancellation in an adapter.

65
00:04:17,820 --> 00:04:25,640
Complex image transformations with minimal memory use automatic memory and disk caching.

66
00:04:25,720 --> 00:04:32,810
So let's scroll down here so let's see actually how we can add this library to our project solaces call

67
00:04:32,840 --> 00:04:33,260
that.

68
00:04:33,370 --> 00:04:34,930
And inside the download section.

69
00:04:34,930 --> 00:04:39,980
Here we have the jar file and we have this cradle quote here.

70
00:04:40,120 --> 00:04:44,060
So we need to add this code to our project just copy this line of code here.

71
00:04:44,080 --> 00:04:48,330
Let's go back to android studio and let's actually open the Android view here.

72
00:04:48,520 --> 00:04:55,210
So here you can see these great scripts open this may be that great fight the module app double click

73
00:04:55,210 --> 00:04:56,720
on it and scroll down.

74
00:04:56,730 --> 00:05:01,480
Here you can see this dependences block here right inside this dependences plug paste.

75
00:05:01,590 --> 00:05:07,540
This line of code here that we actually copied from the Picasso website here and now you can see it

76
00:05:07,530 --> 00:05:12,520
is now a button here that appears here is just click on it in order to see the project.

77
00:05:12,520 --> 00:05:19,480
So let's wait and now we can see that the Picasso library is actually being added to our application.

78
00:05:19,570 --> 00:05:26,890
But if you encounter any problems here at this point of your application make sure that you have updated

79
00:05:26,890 --> 00:05:31,710
the Android repository packages of your Android SDK.

80
00:05:31,870 --> 00:05:37,430
Make sure that you have updated to build tools and redeposited packages and Google Play services.

81
00:05:37,450 --> 00:05:43,140
So we always make sure that you have updated all your packages that you have inside you as well that's

82
00:05:43,150 --> 00:05:46,090
the case so in order to show you how we can update those packages.

83
00:05:46,570 --> 00:05:50,620
If you have a Mac you just need to click on Android studio and then click on preferences.

84
00:05:50,620 --> 00:05:53,930
If you have Windows you just need to click on file settings.

85
00:05:54,010 --> 00:05:56,450
So I just need to click on preferences here.

86
00:05:56,620 --> 00:06:02,800
Now here you can see inside is an appearance and behavior we have the system settings and we have this

87
00:06:02,890 --> 00:06:06,750
Android SDK so you can see these actually.

88
00:06:06,920 --> 00:06:10,490
These a hundred years ago for example there is an update for that.

89
00:06:10,510 --> 00:06:14,280
And right now I get 7.1 point one 1 also.

90
00:06:14,770 --> 00:06:22,210
The Android 8.0 is released but I don't recommend to actually just use it because at this point it may

91
00:06:22,210 --> 00:06:27,850
be a little buggy so let's all wait until a more stable version of Android 8 is released and then use

92
00:06:27,850 --> 00:06:28,530
it.

93
00:06:28,540 --> 00:06:34,810
So for now we're going to use this version and we're seven hundred seven point 1.1 or Android 7.0 or

94
00:06:34,870 --> 00:06:37,010
Android six point zero.

95
00:06:37,270 --> 00:06:42,370
If you want to see the package details you can't just click on this package details here.

96
00:06:42,430 --> 00:06:45,450
So now let's click on SDK tools now.

97
00:06:45,460 --> 00:06:47,810
Make sure that you have installed and updated.

98
00:06:47,810 --> 00:06:55,810
Andrew is the cable tools Android emulator and with STK platform tools Android our support library here

99
00:06:56,080 --> 00:07:02,230
as you can see I have updated the Android support library to the latest version and this one Google

100
00:07:02,670 --> 00:07:05,520
GGP with the blogging tools Google Play.

101
00:07:05,710 --> 00:07:15,340
AP AP extension library Google Play licensing library Google Play services Google Google driver and

102
00:07:15,820 --> 00:07:21,310
make sure that you actually have updated all these packages here and with support repository.

103
00:07:21,460 --> 00:07:22,460
These ones.

104
00:07:22,460 --> 00:07:26,460
So just click on OK now let's go back to Underwoods studio.

105
00:07:26,470 --> 00:07:30,370
And here let's go to our main activity class.

106
00:07:30,370 --> 00:07:33,460
So let me clean this up here in order to make this area wider.

107
00:07:33,460 --> 00:07:39,410
So first of all let's just for example let's just declare a bottom here so just type in here private

108
00:07:40,200 --> 00:07:47,850
BOTTEN PTEN upload image BT and upload image and then put a semicolon here.

109
00:07:47,870 --> 00:07:49,860
Let's go to this uncreate Smurfette.

110
00:07:49,910 --> 00:07:53,240
And here's just typing PTEN upload image assignment operator.

111
00:07:53,240 --> 00:08:01,320
Let's cast this object to our pattern of text find view by id artist Id that PTEN upload image semicolon.

112
00:08:01,370 --> 00:08:07,340
So now let's create a listener for this spot and let's make a spot and a listener to the changes that

113
00:08:07,340 --> 00:08:13,880
is being occurred on the spot and so here I can see Betty and upload image that sets unclick listener.

114
00:08:13,900 --> 00:08:19,630
Now you just hold the shift key on your keyboard and then presently they reach you on your keyboard

115
00:08:19,910 --> 00:08:24,900
so that this option appears uncle at the center and you can see the curly braces and these free dots.

116
00:08:24,980 --> 00:08:29,300
So just select this one and then press and and to your keyboard so the Android studio automatically

117
00:08:29,300 --> 00:08:35,690
put these codes here for you so that this button is now a listener to the clicks or the touch of the

118
00:08:35,690 --> 00:08:36,100
user.

119
00:08:36,200 --> 00:08:38,990
So let's go inside is unclear method here.

120
00:08:39,050 --> 00:08:40,490
Let's create a comment here.

121
00:08:40,490 --> 00:08:41,280
So just step in here.

122
00:08:41,300 --> 00:08:45,850
Upload the image to the server to this server.

123
00:08:46,310 --> 00:08:46,950
Right.

124
00:08:47,060 --> 00:08:54,540
So now let's actually create some references to the firebase instead.

125
00:08:54,540 --> 00:09:00,790
So inside this main activity class let's create a variable of type Firebrace storage such as step in

126
00:09:00,790 --> 00:09:07,900
here private Firebrace storage Firebrace storage and the name of this variable is Firebrace storage

127
00:09:07,940 --> 00:09:08,860
semicolon.

128
00:09:09,010 --> 00:09:11,500
Notice that you are not initializing these valuable here.

129
00:09:11,500 --> 00:09:11,780
Right.

130
00:09:11,810 --> 00:09:19,190
We are just declaring displayable here private and here let's create a variable of type storage reference

131
00:09:19,380 --> 00:09:24,470
so that this variable is going to hold a reference to this for instance.

132
00:09:24,610 --> 00:09:29,060
So so this reference and the name of this value bit is sort of a reference semicolon.

133
00:09:29,440 --> 00:09:31,790
So let me first show you the web browser.

134
00:09:31,810 --> 00:09:37,570
So here enter this you Arel firebase that Google that makes sure that you are assigning to your firebase

135
00:09:37,570 --> 00:09:38,470
account.

136
00:09:38,470 --> 00:09:40,330
And here click on go to console.

137
00:09:40,330 --> 00:09:43,830
So here you can see the firebase protects here right.

138
00:09:43,930 --> 00:09:49,630
So now let's click on our own project upload and download files so you can see that there is a typo

139
00:09:49,630 --> 00:09:50,340
here.

140
00:09:50,410 --> 00:09:53,400
So I forgot to put the P letter here.

141
00:09:53,410 --> 00:09:55,960
So let's click on our project here.

142
00:09:55,960 --> 00:10:00,730
Now you can see that this is our project right let's click on storage and here you can see these two

143
00:10:00,730 --> 00:10:02,850
taps files and rules.

144
00:10:02,860 --> 00:10:03,550
Right.

145
00:10:03,550 --> 00:10:04,560
Let's click on rules.

146
00:10:04,570 --> 00:10:10,720
So here we need to change the rule we need to say that allow read write if requested oath is equal to

147
00:10:10,720 --> 00:10:16,260
null so that anyone can actually upload files to are actually storage here.

148
00:10:16,840 --> 00:10:19,720
It's not really recommended to actually to change the sitting here.

149
00:10:19,730 --> 00:10:26,710
It's not the command to say that everybody can upload files to our backend but for this application

150
00:10:26,740 --> 00:10:33,940
it is OK but later you may want your users to be authenticated inside your application and only the

151
00:10:33,940 --> 00:10:37,470
authenticated users can upload files to the backend.

152
00:10:37,630 --> 00:10:41,300
So let's get we can publish now we can see it's as rules published.

153
00:10:41,320 --> 00:10:42,930
Let's go back to the files tab.

154
00:10:43,030 --> 00:10:44,990
So here you can see this you are right.

155
00:10:44,990 --> 00:10:46,120
Look at look at this you are all here.

156
00:10:46,120 --> 00:10:50,770
This is the you are ill that we can use to upload what we can actually.

157
00:10:50,770 --> 00:10:55,380
We can also manually upload it to our patch and if I click on upload fight here.

158
00:10:55,780 --> 00:11:01,870
So now for example I can select one of these images here for example Fox that is open right now it's

159
00:11:01,870 --> 00:11:09,020
going to upload this image to our backend and later and we can download this image from our patch.

160
00:11:09,270 --> 00:11:16,340
So for now we just want to learn how to upload files using Java codes in Android to Firefox.

161
00:11:16,420 --> 00:11:18,440
So let's go back to android studio.

162
00:11:18,550 --> 00:11:23,170
And here let's initialize our Firebrace storage instance.

163
00:11:23,230 --> 00:11:29,170
So let's go inside these uncreate Smurfit here after this line of code that actually initializers this

164
00:11:29,500 --> 00:11:30,920
PTEN upload image.

165
00:11:31,120 --> 00:11:33,910
I can refer to this firebase storage here.

166
00:11:34,000 --> 00:11:39,670
Assignment operator and here I can say Firebrace storage that gets instance semi-colon.

167
00:11:39,790 --> 00:11:40,160
Right.

168
00:11:40,300 --> 00:11:43,860
So now it's time to initialize our storage reference.

169
00:11:43,900 --> 00:11:52,130
So just typing here storage to our friends storage reference assignment operator and refers to this

170
00:11:52,130 --> 00:11:57,750
firebase smallest instance does get a reference from you or l.

171
00:11:57,800 --> 00:12:00,560
So let's let me show you the web browser here.

172
00:12:00,620 --> 00:12:02,450
So you can see this you are in here right.

173
00:12:02,480 --> 00:12:05,980
If you click on this I can hear it says copy for you.

174
00:12:06,020 --> 00:12:09,540
And let's click on it and it says copy to clipboard.

175
00:12:09,590 --> 00:12:15,590
Let's go back to our Android studio and let's put two quotes here and paste this you are in here right

176
00:12:15,800 --> 00:12:16,740
semicolon.

177
00:12:17,120 --> 00:12:21,070
So now let me create a new line here so that you can see what's going on here.

178
00:12:21,110 --> 00:12:22,700
So it's time to go inside.

179
00:12:22,700 --> 00:12:27,310
It's unclear to me if of this Pythian upload image that's the thanklessly center here.

180
00:12:27,600 --> 00:12:30,080
Now first we need to create an intent.

181
00:12:30,090 --> 00:12:36,380
So just they've been here intent and the name of this internet is going to be image intent image intent

182
00:12:36,440 --> 00:12:42,570
assignment operator new new intent and here inside the apprentice's.

183
00:12:42,680 --> 00:12:48,930
I can't say intent that action Pietsch intent that action.

184
00:12:49,580 --> 00:12:52,560
And then put a semicolon at the end of this line of code here.

185
00:12:52,640 --> 00:13:00,140
So here just type in image intent data sets type and put two codes here and just type in here image

186
00:13:00,350 --> 00:13:04,310
slash and at the end of this line of code just put a semicolon here.

187
00:13:04,310 --> 00:13:07,090
So here we are specifying the type of the intent.

188
00:13:07,100 --> 00:13:08,720
So we are going to access the images.

189
00:13:08,810 --> 00:13:10,930
So the type is going to be Image slash.

190
00:13:11,270 --> 00:13:15,610
And then here we need to call this method start activity for result.

191
00:13:15,650 --> 00:13:18,640
First we need to pass the intense image intent comma.

192
00:13:18,830 --> 00:13:20,740
So here we can specify the request code.

193
00:13:20,740 --> 00:13:25,850
So for this specific application I'm going to pass that number one here if you want to we can create

194
00:13:26,000 --> 00:13:30,330
a constant that holds this value number one and then each and past is constant here.

195
00:13:30,350 --> 00:13:34,100
But for this application I just pass that value and number one here.

196
00:13:34,100 --> 00:13:35,540
Let's scroll down here.

197
00:13:35,690 --> 00:13:39,870
And before the end in curly brace of these main activity class.

198
00:13:39,890 --> 00:13:45,280
So here we need to override the unactivated result method on activity result.

199
00:13:45,290 --> 00:13:51,230
So this method is going to be executed when the user has selected an image from the gallery or anywhere

200
00:13:51,230 --> 00:13:55,660
else and they use it is actually come back to the main activity.

201
00:13:55,670 --> 00:13:58,180
Now the NITV to resolve if it is called.

202
00:13:58,310 --> 00:14:04,130
So that's why here inside these Uncle Mefford we said start activity for results because we want to

203
00:14:04,130 --> 00:14:08,160
get a result from that specific activity this image into it actually.

204
00:14:08,390 --> 00:14:14,620
So inside this activity result I can create an if statement or I can actually create a switch statement

205
00:14:14,640 --> 00:14:16,880
or switch switch request code.

206
00:14:16,960 --> 00:14:21,250
Right and then open and close this switch statement by using the curly braces here.

207
00:14:21,470 --> 00:14:25,750
So here we passed number one as the request to the Smif at right.

208
00:14:25,940 --> 00:14:26,870
So here I can say.

209
00:14:26,870 --> 00:14:29,710
Case number one colon.

210
00:14:29,750 --> 00:14:34,220
So he had notice that we are referring to this request called argument of this unactivated is augmented.

211
00:14:34,220 --> 00:14:34,880
Right.

212
00:14:34,880 --> 00:14:38,810
Case Number one if there is that request code is actually number one.

213
00:14:39,030 --> 00:14:44,420
I can create an if statement here so if result call it now I'm going to refer to this result called

214
00:14:44,450 --> 00:14:48,460
arguments so if resolved code is equal to the result.

215
00:14:48,470 --> 00:14:49,260
OK.

216
00:14:49,310 --> 00:14:52,570
So now open and close this if statement by using these curly braces here.

217
00:14:52,580 --> 00:14:53,790
So not just after this.

218
00:14:53,810 --> 00:14:58,120
Notice that after this case statement make sure to actually put this break statement here.

219
00:14:58,130 --> 00:14:58,710
Right.

220
00:14:58,820 --> 00:15:05,540
So now inside these if statement we can't say so or not is that the Smurfit has this argument of type

221
00:15:05,570 --> 00:15:06,680
intent and it is data.

222
00:15:06,670 --> 00:15:07,140
Right.

223
00:15:07,340 --> 00:15:09,900
So we get that data from the image intent.

224
00:15:10,100 --> 00:15:15,460
So first we need to access the user of that specific image that is selected by the user.

225
00:15:15,560 --> 00:15:17,930
So we can create a value of that you are here.

226
00:15:17,930 --> 00:15:19,510
So you are right you are right.

227
00:15:20,210 --> 00:15:22,260
And the name of this valuable is image.

228
00:15:22,280 --> 00:15:26,430
You are the image you are the assignment operator.

229
00:15:26,480 --> 00:15:31,500
Now refer to these arguments name data that get data.

230
00:15:31,530 --> 00:15:36,830
So notice that this that gets the time if it actually returns a value of type you are.

231
00:15:36,830 --> 00:15:42,710
I soon notice that these data type here determines or specifies the return type of the Smurfette which

232
00:15:42,710 --> 00:15:44,200
is going to be you are right.

233
00:15:44,210 --> 00:15:48,920
So just select the Smurfette and then press on and end up with a semicolon at the end of this line of

234
00:15:48,920 --> 00:15:49,700
code here.

235
00:15:49,910 --> 00:15:52,810
So now that we have this image you are right you can say.

236
00:15:52,880 --> 00:15:59,320
So let's create a variable of types thought its reference in order to hold the reference of the images

237
00:15:59,330 --> 00:16:01,570
that you're going to have inside our backend.

238
00:16:01,730 --> 00:16:08,690
So solicitor or offense and the name of this variable is going to be Image address image address in

239
00:16:08,930 --> 00:16:11,380
Firebrace assignment operator.

240
00:16:11,630 --> 00:16:17,390
So now let's refer to our store as reference variable that we created above inside this class.

241
00:16:17,390 --> 00:16:18,360
So just typing here.

242
00:16:18,480 --> 00:16:20,820
So our friends thought so.

243
00:16:20,840 --> 00:16:24,490
Because I want to actually create a folder inside our backend.

244
00:16:24,500 --> 00:16:25,840
I'm going to create a chart.

245
00:16:25,970 --> 00:16:30,830
So you're already familiar with these concepts because they are in their fiber section of course.

246
00:16:30,830 --> 00:16:38,150
I talked a lot about how we can create a child how we can create a folder and how you can put your actually

247
00:16:38,150 --> 00:16:40,840
files or data inside those forth.

248
00:16:41,000 --> 00:16:46,440
So I'm going to create the child the name of this child is going to be images.

249
00:16:46,580 --> 00:16:47,280
Right.

250
00:16:47,340 --> 00:16:55,230
So now I want to put this image that the user has selected two into these images folder so I can say

251
00:16:55,400 --> 00:16:56,880
again that child.

252
00:16:56,970 --> 00:17:03,210
And now I'm going to refer to this image you are right so you can say image you or I did not get last

253
00:17:03,230 --> 00:17:09,190
paff segment so this is going to be an address of that specific image that the user has selected.

254
00:17:09,360 --> 00:17:16,400
If you want to you can create unique image names you know how to do that in the previous two tutorials.

255
00:17:16,410 --> 00:17:21,870
I thought how you can create unique names so that you can actually use them inside your applications.

256
00:17:21,870 --> 00:17:25,800
But for now I just want to use that last puff segment semi-colon.

257
00:17:25,890 --> 00:17:28,670
So now let's create a new line here.

258
00:17:28,680 --> 00:17:31,630
Let's create on line here and now after this line of code.

259
00:17:31,680 --> 00:17:38,010
So in order to see that whether the image is actually uploaded to Firebrace or not.

260
00:17:38,100 --> 00:17:43,860
We need to actually create an on a successor listener for these addressee or for this sort of reference

261
00:17:43,920 --> 00:17:45,240
image address in firebase.

262
00:17:45,360 --> 00:17:53,310
But before that we need to put the image into this address so we can say image address in firebase that

263
00:17:53,340 --> 00:17:55,060
put file.

264
00:17:55,170 --> 00:17:58,260
So not that this if it needs an argument of type you or I.

265
00:17:58,320 --> 00:17:59,730
So we have this you are right.

266
00:17:59,760 --> 00:18:00,740
Image You are right.

267
00:18:00,930 --> 00:18:04,130
And here I can say that at on success.

268
00:18:04,140 --> 00:18:09,220
Listener and just they've been here new and hold the shift key on your keyboard.

269
00:18:09,230 --> 00:18:13,790
And the person then they're all on your keyboard and it says unsuccessfully send right.

270
00:18:13,820 --> 00:18:15,900
Select this one and then put us on it which I knew.

271
00:18:15,920 --> 00:18:20,830
So now the Android studio puts these lines of code here automatically for you.

272
00:18:20,830 --> 00:18:25,790
So let me create a new line you know so that you can see the entire codes that are generated here.

273
00:18:25,790 --> 00:18:26,600
Right.

274
00:18:26,600 --> 00:18:28,240
These are the codes that are generated here.

275
00:18:28,400 --> 00:18:34,410
E-mail address in firebase that putrified image you are right that ad unsuccessfully Center new unsuccess

276
00:18:34,410 --> 00:18:38,040
listener upload task or task snapshots.

277
00:18:38,420 --> 00:18:44,420
So the task snapshot is going to have the you are right that we need in order to actually download the

278
00:18:44,420 --> 00:18:49,700
image later we are not going to use it now but we're going to actually use it later when we want to

279
00:18:49,700 --> 00:18:52,070
download the image and put it into our image.

280
00:18:52,370 --> 00:18:54,290
So this is the unsuccess method right.

281
00:18:54,320 --> 00:19:00,050
The unsuccess method is going to be called then the uploading task is actually successful.

282
00:19:00,320 --> 00:19:04,420
And when the image is successfully uploaded to their firebase.

283
00:19:04,520 --> 00:19:10,520
But what happens if the image is not actually successfully uploaded to the firebase.

284
00:19:10,580 --> 00:19:13,650
In that case we have actually an on failure it.

285
00:19:13,820 --> 00:19:15,860
So let's put this in parenthesis here.

286
00:19:15,860 --> 00:19:18,270
There is an error here it says put a semicolon here.

287
00:19:18,530 --> 00:19:25,310
So don't put a semicolon here just put that here and select this one add on failure center and then

288
00:19:25,310 --> 00:19:28,640
press and attention your keyboard and inside the apprentice's just open here.

289
00:19:28,730 --> 00:19:33,830
You again hold the shift key on your keyboard and then press on the letter or key on your keyboard and

290
00:19:33,830 --> 00:19:39,760
select this one on phileo listener and then present it to you on your keyboard so you can see that we

291
00:19:39,770 --> 00:19:41,100
have this unfairly on my face.

292
00:19:41,120 --> 00:19:48,130
So this is going to be executed when the uploading task was not successful and it actually failed.

293
00:19:48,140 --> 00:19:51,620
So let's actually put a semicolon here at the end of this Prentice's here.

294
00:19:51,620 --> 00:19:53,650
So now we have no errors right.

295
00:19:53,690 --> 00:19:56,000
So let's go inside is unsuccess Smurfette.

296
00:19:56,030 --> 00:20:01,820
Let's create a toast message toast that make takes the first minute to pass the context.

297
00:20:01,880 --> 00:20:08,380
Don't just talk to typing this year because if you put this year here we actually created an anonymous

298
00:20:08,390 --> 00:20:13,750
in a class that actually implements this unsuccessfully center interface.

299
00:20:13,760 --> 00:20:20,870
So this here refers to that anonymous class not this main activity context so the context is actually

300
00:20:20,870 --> 00:20:21,830
the main activity.

301
00:20:21,890 --> 00:20:28,170
So just typing here main activity that this has the context come up put two quotes here.

302
00:20:28,280 --> 00:20:30,150
So now we need to put the message here right.

303
00:20:30,170 --> 00:20:37,570
And here I can say uploading was successful Let's put an exclamation mark here come up.

304
00:20:37,650 --> 00:20:44,300
And here we just need to specify the duration of the message so they can hear and launch that show.

305
00:20:44,460 --> 00:20:44,860
Right.

306
00:20:44,940 --> 00:20:49,850
Let's copy this line of code and let's put it here inside this unfairly and method too.

307
00:20:50,220 --> 00:20:59,040
And this time we can say uploading was not successful uploading was not successful and that's it.

308
00:20:59,040 --> 00:21:02,090
So now it's time to run the application.

309
00:21:02,100 --> 00:21:04,880
So let's run the application and let's see what happens now.

310
00:21:04,950 --> 00:21:07,950
So just select one of these devices and then click on OK.

311
00:21:08,130 --> 00:21:13,740
So now you can see that I opened the other browser here and I want to show you the emulator here.

312
00:21:13,740 --> 00:21:16,710
So let's click on this button upload the image to Firebrace.

313
00:21:16,710 --> 00:21:22,290
So it's going to actually open the gallery for us so I have actually taken these images if you want

314
00:21:22,290 --> 00:21:22,690
to.

315
00:21:22,740 --> 00:21:29,130
You can actually to use the camera of the emulator here and then you can actually just take some pictures

316
00:21:29,130 --> 00:21:29,860
here.

317
00:21:30,210 --> 00:21:32,780
Let's go back to our app here.

318
00:21:33,120 --> 00:21:34,990
Upload and download files.

319
00:21:35,040 --> 00:21:41,170
So select one of these images and now you can see that our application crashed.

320
00:21:41,220 --> 00:21:42,240
There is a problem here.

321
00:21:42,240 --> 00:21:45,270
Let's go back to android studio now.

322
00:21:45,570 --> 00:21:47,220
If you want to find the error.

323
00:21:47,250 --> 00:21:49,140
I just need to click on this android monitor.

324
00:21:49,140 --> 00:21:53,420
So let me show you the error here and here look at these lines of code here.

325
00:21:53,430 --> 00:21:55,630
These these are the texts actually.

326
00:21:55,860 --> 00:22:01,690
And it says Jobar that line that security except exception permission denied.

327
00:22:01,980 --> 00:22:04,370
So there is a permission error here.

328
00:22:04,660 --> 00:22:10,410
And if I show you it says that we need to have read external storage permission this is actually a dangerous

329
00:22:10,410 --> 00:22:14,280
permission and we need to actually declare this permission.

330
00:22:14,280 --> 00:22:18,100
In both of our files the manifest file and the job of life.

331
00:22:18,270 --> 00:22:23,120
So let's go to our Android studio and here let's open the ad with you.

332
00:22:23,120 --> 00:22:25,080
Let's just double click on this manifests here.

333
00:22:25,260 --> 00:22:28,740
So let me stop here in order to make this area right there.

334
00:22:28,740 --> 00:22:32,490
So let me just put the spin machine here inside this manifest.

335
00:22:32,630 --> 00:22:37,280
So just open it up and just type in here use this permission and just type in here right.

336
00:22:37,290 --> 00:22:39,210
External storage right.

337
00:22:39,270 --> 00:22:45,180
External storage and just disclosed is that if you choose a right external storage your application

338
00:22:45,180 --> 00:22:49,080
is going to have also permission to read the external storage.

339
00:22:49,080 --> 00:22:55,320
Your application is going to have to the permission to read and write the external storage.

340
00:22:55,320 --> 00:23:00,410
So let's go to automate an activity class let's scroll to the top here and now here.

341
00:23:00,420 --> 00:23:06,680
After declaring Desplat in here we need to actually say that you're going to have our permission.

342
00:23:06,730 --> 00:23:11,460
We are going to ask the user to give us the permission to access their external storage.

343
00:23:11,610 --> 00:23:13,390
So just create a variable of type integer.

344
00:23:13,390 --> 00:23:15,030
Here inside is uncreate Mefford.

345
00:23:15,330 --> 00:23:19,280
And then the name of this variable is going to be permission result.

346
00:23:19,530 --> 00:23:25,400
Assignment operator and just type in here context compact that chick's self permission.

347
00:23:25,650 --> 00:23:31,710
So for the first argument we need to pass the context so the context is main activity that this come

348
00:23:31,710 --> 00:23:32,200
on.

349
00:23:32,460 --> 00:23:38,040
And the second argument is going to be just type in here manifest.

350
00:23:38,340 --> 00:23:41,320
So choose this one here and manifest Prentice's Android.

351
00:23:41,430 --> 00:23:41,880
OK.

352
00:23:41,970 --> 00:23:44,900
That permission that's right.

353
00:23:44,910 --> 00:23:47,430
External sort of streite external storage.

354
00:23:47,430 --> 00:23:49,990
So this is our permission write permission resolved.

355
00:23:50,190 --> 00:23:52,130
So let me create a new line here.

356
00:23:52,140 --> 00:23:59,160
So now that we have this permission result let's actually create an if statement so if permission result

357
00:23:59,700 --> 00:24:03,680
is equal to package manager that permission granted.

358
00:24:03,930 --> 00:24:09,540
This means that if the user has actually given us the permission to access the external storage then

359
00:24:10,020 --> 00:24:14,790
we can actually put some lines of code here but we can actually we need to create an else statement

360
00:24:14,820 --> 00:24:21,990
here in case the user doesn't give us actually permission to access that external storage.

361
00:24:21,990 --> 00:24:24,030
So in that case we can actually say.

