1
00:00:00,240 --> 00:00:01,100
Hello everyone.

2
00:00:01,110 --> 00:00:07,800
So it is the story I want to tell you that because we want to access the user's location we want to

3
00:00:07,890 --> 00:00:11,040
we need to actually to first ask for the permission.

4
00:00:11,040 --> 00:00:16,140
So it's very important that first we must actually ask for the parent permission because we want to

5
00:00:16,140 --> 00:00:21,300
access the use that it's location and it is actually called a dangerous permissions so we must ask.

6
00:00:21,750 --> 00:00:26,660
First of all we need to actually put that permission inside the manifest file so that I should add that

7
00:00:26,660 --> 00:00:30,510
up just click on View and then tool windows and that we can project.

8
00:00:30,630 --> 00:00:36,520
So as you can see the shortcut for the match is comment 1 if you are using a Windows machine the shortcut

9
00:00:36,520 --> 00:00:37,880
should be must be different.

10
00:00:37,890 --> 00:00:40,420
So I think it is actually control one.

11
00:00:40,590 --> 00:00:41,510
So just click on it.

12
00:00:43,010 --> 00:00:49,420
So here let's actually open the app folder here and then let's double click on this manifests here.

13
00:00:49,580 --> 00:00:54,550
If you don't have this manifest file here you just to open this folder and it is actually the object

14
00:00:54,640 --> 00:00:55,810
manifesto and fight.

15
00:00:56,060 --> 00:00:59,690
So let me double click on this tab and write manifested XML.

16
00:00:59,900 --> 00:01:06,620
So inside this android manifested exemplified here after the ending tag of this manifest and before

17
00:01:06,620 --> 00:01:07,260
the ending.

18
00:01:07,310 --> 00:01:10,160
Or should it be for this application.

19
00:01:10,490 --> 00:01:16,340
I would actually put these permissions here which is open attack and just type in here use is permission

20
00:01:17,300 --> 00:01:21,650
and the name is going to be course location and access course location.

21
00:01:21,650 --> 00:01:23,140
So what is this permission.

22
00:01:23,300 --> 00:01:29,300
It is actually that the permission that is going to give us the location actually the approximate location

23
00:01:29,360 --> 00:01:31,130
of the users device.

24
00:01:31,200 --> 00:01:31,640
OK.

25
00:01:31,790 --> 00:01:35,730
So the course of course location is going to give us the approximate location.

26
00:01:35,750 --> 00:01:38,590
We have another location called Falling location.

27
00:01:38,600 --> 00:01:43,800
So it is the final location is a little bit more actually exact it is more precise.

28
00:01:44,120 --> 00:01:49,370
But the problem with accessing a final location is that it going to actually eat more battery.

29
00:01:49,370 --> 00:01:55,020
So we are going to stick with this one access course location is actually enough for this application.

30
00:01:55,040 --> 00:01:56,750
It's going to just give us the approximate location.

31
00:01:56,750 --> 00:02:02,960
So let's put up a slash and the end in type in order to actually close the stack here.

32
00:02:02,960 --> 00:02:03,970
So that's it.

33
00:02:04,040 --> 00:02:07,030
And now we need to actually at the meditator.

34
00:02:07,330 --> 00:02:09,830
OK so let's see how we can do that.

35
00:02:09,830 --> 00:02:15,920
So now you may ask that so why we have to add them to the top because we need to tell the Andray manifest

36
00:02:16,190 --> 00:02:18,950
that we are going to use the Google Play services.

37
00:02:18,950 --> 00:02:21,250
So it is very important that we at the Met at 8am.

38
00:02:21,380 --> 00:02:25,510
So after you can see this application Typepad here right it is actually their starting.

39
00:02:25,730 --> 00:02:27,740
And it is the ending tag here.

40
00:02:27,740 --> 00:02:28,350
Right.

41
00:02:28,370 --> 00:02:32,600
So after this starting tag and before these activities here.

42
00:02:32,770 --> 00:02:33,050
OK.

43
00:02:33,050 --> 00:02:34,460
I created some space.

44
00:02:34,460 --> 00:02:37,400
Here it is the place actually to add the metadata.

45
00:02:37,400 --> 00:02:40,180
So just open it and just typing here Mr. data.

46
00:02:40,670 --> 00:02:45,590
And then here let's actually create a new line here let me create on your line and just type in here

47
00:02:45,980 --> 00:02:49,300
actually name and inside the quotes here.

48
00:02:49,370 --> 00:02:57,280
Just type in here come that Google dot Android dot GM s dot version.

49
00:02:57,800 --> 00:02:59,270
OK that version.

50
00:02:59,720 --> 00:03:03,790
And then here as you can see we added this name here right.

51
00:03:03,800 --> 00:03:09,260
You need to actually add another value here and it is actually called value.

52
00:03:09,290 --> 00:03:15,260
So just type in here value and here this is value right so inside the quotes instead of course just

53
00:03:15,260 --> 00:03:19,270
typing here at sign integer and just typing here.

54
00:03:19,270 --> 00:03:21,180
Google Play services version.

55
00:03:21,190 --> 00:03:26,560
So the autocomplete feature of Android studio is going to help you to choose this one so just pleasant

56
00:03:27,050 --> 00:03:32,770
person on your keyboard and in order to end this tablet you're going to self-closing this like right.

57
00:03:32,890 --> 00:03:39,020
I just need to put on slash here and here you can see that the Android to do you put this into here

58
00:03:39,040 --> 00:03:40,260
for me automatically.

59
00:03:40,330 --> 00:03:40,810
Right.

60
00:03:41,020 --> 00:03:42,960
So this is our metadata.

61
00:03:43,180 --> 00:03:49,630
And here I want to specify that this application is going to be used only in portrait mode not in landscape

62
00:03:49,630 --> 00:03:52,470
mode but only in portrait mode so how we can do that.

63
00:03:52,570 --> 00:03:55,940
So here you can see it is actually activity tach right.

64
00:03:55,960 --> 00:03:57,800
This is actually distorting Tadg.

65
00:03:57,940 --> 00:04:00,900
So here it says android named main activity.

66
00:04:01,000 --> 00:04:08,960
Let's actually create our space here and here just type the screen orientation screen orientation and

67
00:04:09,520 --> 00:04:12,380
just choose portrait's right.

68
00:04:12,380 --> 00:04:18,060
So now here we are telling the activity that this activity here main activity is going to be only used

69
00:04:18,380 --> 00:04:21,050
in portraits mode not in landscape mode.

70
00:04:21,110 --> 00:04:22,220
OK.

71
00:04:22,220 --> 00:04:23,370
So that's it.

72
00:04:23,720 --> 00:04:28,400
And now we actually added all the codes that we needed for now.

73
00:04:28,460 --> 00:04:32,820
OK so far we've added all the cards that we needed here to these and manifest why.

74
00:04:32,870 --> 00:04:38,380
So now it's time to go to the main activity class and here you can see these fits right.

75
00:04:38,390 --> 00:04:39,000
Right.

76
00:04:39,080 --> 00:04:44,520
So now I'm going to actually create a new method inside these main activity and inside this man I can

77
00:04:44,550 --> 00:04:50,370
declasse actually so at the top of the bottom of the fight after the ending curly brace of this on can

78
00:04:50,380 --> 00:04:50,990
action fake.

79
00:04:51,020 --> 00:04:56,540
I'm going to create m if I want to create a comment here that says I should custom if it's like a custom

80
00:04:57,120 --> 00:04:57,610
methods.

81
00:04:57,770 --> 00:05:01,120
So the custom effects are the methods that I actually added myself.

82
00:05:01,280 --> 00:05:01,740
OK.

83
00:05:01,970 --> 00:05:05,160
So let's put these Misfit's here below this comment.

84
00:05:05,220 --> 00:05:10,760
So because we are going to use this method only inside this main activity class we can actually declare

85
00:05:10,800 --> 00:05:12,620
RMF as private for now.

86
00:05:12,710 --> 00:05:13,160
OK.

87
00:05:13,220 --> 00:05:16,040
Later we may want to actually to change this access modifier.

88
00:05:16,040 --> 00:05:22,850
But for now I just want to use this method inside this main activity class so private and return type

89
00:05:22,850 --> 00:05:29,780
of this method is going to be void and the name of this Smurfette is going to be actually show the user

90
00:05:31,480 --> 00:05:38,350
location write and put up that apprentices this movie is not going to accept any prime interest and

91
00:05:38,350 --> 00:05:41,120
just open and close the Smurfit by using these curly braces.

92
00:05:41,140 --> 00:05:49,690
So inside this method first we need to actually ask the user in order to give us the permission in order

93
00:05:49,690 --> 00:05:51,740
to access the location.

94
00:05:51,760 --> 00:05:52,140
OK.

95
00:05:52,240 --> 00:05:54,300
So it is called runtime permission.

96
00:05:54,310 --> 00:05:58,690
We must ask the user because it is actually necessary.

97
00:05:58,690 --> 00:06:00,740
It is called A Dangerous permission.

98
00:06:00,850 --> 00:06:06,730
In Android to access the user's location so the user must be actually aware of that permission.

99
00:06:06,730 --> 00:06:09,240
So it is called a runtime permission.

100
00:06:09,250 --> 00:06:10,650
So let's see how we can do that.

101
00:06:10,660 --> 00:06:15,670
First let's create a variable of type in teacher and the name of this variable is going to be permission

102
00:06:15,670 --> 00:06:24,220
check permission check and put an assignment operator here and just type in here context compacts that

103
00:06:24,520 --> 00:06:26,560
check self permission.

104
00:06:27,540 --> 00:06:31,180
First if it actually accepts two arguments the first one is the context.

105
00:06:31,180 --> 00:06:35,900
So the context is main activity right because the main activity is going to actually access the location.

106
00:06:35,910 --> 00:06:42,500
So main activity that this is the context the comma the second argument is going to be the actual permission.

107
00:06:42,540 --> 00:06:47,970
So because we want to access the user's location the users approximate location actually I'm going to

108
00:06:48,150 --> 00:06:51,550
just type in here and manifest that permission.

109
00:06:51,840 --> 00:06:53,240
That just they've been here.

110
00:06:53,250 --> 00:06:55,940
Course we've chapiter c course location.

111
00:06:56,160 --> 00:07:00,420
So it's going to put the actual name here automatically for us and then put a semicolon at the end of

112
00:07:00,420 --> 00:07:01,200
this statement.

113
00:07:01,410 --> 00:07:04,910
So let me ask you to create a new line here so that you can see these values.

114
00:07:04,920 --> 00:07:09,390
So as you can see if we create that are valuable if that is your permission check and we assign this

115
00:07:09,390 --> 00:07:13,520
value to this valuable context compact that checks of permission.

116
00:07:13,740 --> 00:07:15,650
And as the arguments first.

117
00:07:15,660 --> 00:07:18,060
We need to pass the the context.

118
00:07:18,240 --> 00:07:20,740
And the second argument is going to be the actual location.

119
00:07:20,760 --> 00:07:26,070
So this code here is going to actually return a value of that material and it's and it is going to be

120
00:07:26,070 --> 00:07:27,840
assigned to this body of it.

121
00:07:28,020 --> 00:07:31,600
So now I can create an if statement right.

122
00:07:31,620 --> 00:07:41,450
I can actually say if permission check is equal to package manager that permission granted.

123
00:07:41,450 --> 00:07:47,770
So as you can see I need to put a capital P in order to actually see the autocomplete feature ID or

124
00:07:47,770 --> 00:07:49,910
to complete the options here.

125
00:07:50,060 --> 00:07:51,750
So it was permission granted.

126
00:07:51,770 --> 00:07:57,650
So this means that if their permission to value is equal to the Permission granted here this means that

127
00:07:57,710 --> 00:08:03,260
the user has actually gave us their permission to access the location right.

128
00:08:03,260 --> 00:08:07,610
In that case we can actually open and close this method by using the curly braces.

129
00:08:07,790 --> 00:08:09,980
So let's create an else statement here.

130
00:08:10,040 --> 00:08:16,520
LS So else means what else means that this expression he had evaluated to false.

131
00:08:16,550 --> 00:08:19,690
So now it is going to execute this else it's.

132
00:08:19,850 --> 00:08:26,330
So in that case if this condition is false and the user actually denied to access the location the right

133
00:08:26,480 --> 00:08:30,050
to access the location in that case you are going to execute this statement.

134
00:08:30,050 --> 00:08:36,890
So here I can't just CTX the location that a said text and I can just put two codes here and here I

135
00:08:36,890 --> 00:08:46,040
can say this app is not allowed to access the location.

136
00:08:46,170 --> 00:08:46,970
Right.

137
00:08:46,980 --> 00:08:49,970
So this is the else statement and that is actually to go inside this.

138
00:08:49,990 --> 00:08:54,840
And so this means that the user has actually gave us that the actually the permission so we can actually

139
00:08:54,840 --> 00:08:55,900
put the quotes here.

140
00:08:56,040 --> 00:08:57,380
But inside this Elsa's statement.

141
00:08:57,390 --> 00:08:59,790
Let's add another quote here it is.

142
00:08:59,790 --> 00:09:04,130
This means that the user is not actually doesn't allow us to access the location right.

143
00:09:04,140 --> 00:09:09,990
So we can actually ask the user we can actually create our requests here in order to ask the user to

144
00:09:10,020 --> 00:09:14,970
give this application the permission to access the location.

145
00:09:14,970 --> 00:09:16,680
So let's see how we can do that.

146
00:09:16,680 --> 00:09:20,480
So I'm going to paste this line of code here and then I'm going to explain to you what's going on here.

147
00:09:20,490 --> 00:09:21,510
Exactly.

148
00:09:21,510 --> 00:09:23,820
So as you can see I actually pasted this line of code here.

149
00:09:23,820 --> 00:09:27,920
It says activity compact that request permissions.

150
00:09:28,080 --> 00:09:31,160
So it is going to actually actually create a request.

151
00:09:31,160 --> 00:09:33,210
I was going to ask the user to access the location.

152
00:09:33,210 --> 00:09:36,350
First we need to pass the context main activity that this come up.

153
00:09:36,510 --> 00:09:39,180
And the second argument is this one new stream.

154
00:09:39,180 --> 00:09:42,590
So here it is going to create the paramecia right streamed.

155
00:09:42,660 --> 00:09:46,040
It is actually an array right new An at a upstreams.

156
00:09:46,440 --> 00:09:48,950
And as the first value of this.

157
00:09:48,990 --> 00:09:54,090
Here we are going to pass this value inside the curly braces manifest that permission that access course

158
00:09:54,090 --> 00:10:01,090
location come up here and it is actually to devalue number one here so what is this value let me actually

159
00:10:01,090 --> 00:10:04,270
just again type this out here again.

160
00:10:04,270 --> 00:10:11,710
So the first value is activity Compaq's write activity compact that request permissions.

161
00:10:11,710 --> 00:10:14,450
So let me tell you this is actually the request code.

162
00:10:14,500 --> 00:10:16,520
Ok the first argument is the request code.

163
00:10:16,660 --> 00:10:20,920
So here I just this is actually just a simple request right.

164
00:10:20,950 --> 00:10:22,040
So I just passed the value.

165
00:10:22,040 --> 00:10:27,310
Number one if you want to you can actually change it to any other values or you can just create a constant

166
00:10:27,310 --> 00:10:32,010
for this value but it is just a simple request or just past the value number one.

167
00:10:32,140 --> 00:10:32,700
OK.

168
00:10:33,010 --> 00:10:38,020
So make sure that it is actually a unique value that you are not using inside your application.

169
00:10:38,020 --> 00:10:41,140
So number one is not use the inside for that application.

170
00:10:41,140 --> 00:10:43,390
So I just pass on to that number one here.

171
00:10:43,420 --> 00:10:47,630
So now we can go inside this statement.

