So now in order to create a class in our project first I need to click on find Neal and then click on
Java class.
So now for the name of our class just type in here.
SD card checker Okay.
And then click on OK.
So as you can see here this is our SD card check here.
Our class.
OK.
So in this class.
In this class I just want to actually to check whether we can actually write or read from the SD card.
Ok now I'm going to actually paste in some lines of code here and then I'm going to explain to you what's
going on here.
So as you can see here these are the lines of code that they actually pasted here.
OK.
Or if I pasted this method here as you can see.
So first of all let me explain to you that the access modifier of the Smurfit that they actually pasted
here is public.
And as you can see here this method is static.
So we can actually refer to this method by using the name of this class.
As the card check here that the name of the Smurfette.
OK.
And as you can see here the return type of this method is void.
Check whether external storage available or not.
OK so this is the name of this Mefford.
OK.
And this pivot actually accepts a context as you can see here the argument of this if it is context.
And now inside this method I have two variables of type Boolean.
The first one is is external storage available.
And as you can see here I assigned the value of false to this variable OK.
And the second one as you can see here is is external storage writable.
And as you can see here the default value that I assigned to the symmetry about is false.
So here as you can see I created another value but of type is strange and the name of this variable
is state.
And as you can see here I assigned this value to the Suadi environment that get external storage state.
So it's going actually to check for that we can actually write or actually read from the SD card or
not.
OK.
Environment that get external storage.
So that value is going to be actually assigned to this state rowdier But and here I create it.
And if else statement as you can see here if environment that media mounted that equals state.
So this means that whether we can actually read and write the media on the SD card or not.
OK.
Environment that media mounted that equals state vision.
What we can read and write the media also if this expression evaluates to true then we can actually
read and write the media on the SD card and then as you can see here is external storage available.
This value is variable assignment operator is external storage writable.
This variable assignment operator.
True.
So I assign the value true to both of these variables to two both of these boolean variables.
So we could actually write our code in this way.
OK.
Is external storage available.
Assignment operator is external storage writable assignment operator.
True.
And here I created a toast in order to show the user that we can actually read and write from the SD
card.
As you can see here toast that make text first of all I actually put the context as you can see that
we actually receive as an argument from the Smurfit context.
The second one is the actually the message that I want to show to the user.
Read and write and the first one is the length of the actually the message that you want to show to
the use that the duration of the message that they want to show to the user.
And I called this first show on these talks object and I have an ELSE IF statement.
So if this expression evaluates to false then this expression is going to be evaluated.
ELSE IF.
ELSE IF environment that Medio mounted read only that equals state.
So in this way we can all we can only read the media from the SD card.
OK.
If this expression evaluates to true then we can only treat the media and then assign a value to.
This is this is external storage available.
True.
And I assigned the value files is external storage rightabout false as you can see here.
And then I created a host object host that make text.
First of all it is actually a scientist context for the first argument of this to make text Merfeld.
And you can see here we receive this context as an argument of the Smurfette and then the second one
is the message and the first one is the duration of the message that I want to show to the user.
And I called this show my friend and this object tossed object.
And we have an else statements here.
So if both of these expressions evaluates to false then this expression and say This statement is going
to be executed and neither read nor write.
And the SD card is external storage available.
Assignment operator is external storage writable assignment operator false.
So I assigned the value false to both of these a boolean value else here as you can see here and that
I created a toast object in order to show to the user that we can neither read nor write on the SD card.
OK.
So hopefully that makes sense.
And now let's actually go back inside our our main activity the java file here.
So inside our main activity file as you can see now you can actually call the Smurfit.
So first of all because this is actually a static method we can actually we can actually choose to refer
to the name of this class and then I put a dot operator and then I can actually refer to the name of
the Smurfit.
So here I am just typing an SD card Take care.
So I referred to the name of this class that I created inside our project that SD card check hair that
check whether external storage available or not.
And now we can actually assign the value of value of type context.
So context is this our class main activity that this.
And now let's actually run our project and see what happens.
So now as you can see it says lead and right.
OK.
So if we can actually read and write on the SD card.
OK.
So hopefully that makes sense.
And now it's actually putting some more lines of code inside.
Our main activity class.
So now I'm going to actually pasting some lines of code here inside this main activity class and then
I'm going to explain to you what's going on here.
Here I'm going to actually declare some user interface components inside the main activity class.
So as you can see here these are the lines of code that they actually pasted inside this main activity
class.
So first of all I actually created a button as you can see here between downloads folder.
So as you can see I'm just declaring this button here.
I'm not instantiating this project.
Disputant OK.
I'm just declaring this button.
And here I actually declared and added a button between the music folder between documents folder between
ringtones folder BATNA podcasts folders as you can see here we have these buttons here.
OK.
Download their music file their documents folder ringtones ringtones folder and so on.
And as he has said he had Pythian about a test folder between the movies folder PTEN alarm's folder
PTEN Pictures folder as you can see.
And I have between pretty safe file.
EDT value added text.
So as you can see here I declared an edit text object here.
And I have another button here between the retrieve info and I have a text view takes the value here
I declared and image view and him on and here as you can see I declared and added a button between allow
access pictures and as you can see here I declared and are linearly layouts here as you can see linearly
out linearly and horizontal image through each image suture.
So now let's actually instantiate these objects that they actually declared inside this main activity
class.
So inside this uncreate Smurfette after this line of code I'm going to instantiate those objects.
So now here I went actually pasting some lines of code inside this uncreate method.
And then I'm going to explain to you what's going on here.
So as you can see here these are the lines of code that I actually pasted here inside this uncreate
method.
And as you can see here I am actually instantiating the objects that I actually declared inside the
main activity class so that they can see BTA and download folder as you can see here.
And it says between download directory.
OK so because we want to actually create directories inside our For example downloads folder we can
either call it download folder between downloads folder or download our directory.
OK.
It doesn't make any difference.
But here I just wanted to show you that you can actually create a folder in site up for example and
other directed in music for example for that.
OK.
So you can call it music directory or music folder or download directory or download folder and here
as you can see I have Pythian music folder between music directory and here between documents folder
and here as you can see between documents folder between our ringtones folder B.T. and process folder
between movies folder and alarm's folder Pythian pictures folder pity and save file as you can see it
is this the button is for this button as you can see we have a safe button here for actually saving
some data to a file inside our documents folder as you can see here between savefile.
And we have another button for retrieving those data inside another file in SD card.
And this is the ID for that BT and retrieve the info.
And if I go back and say this main activity that java file here we have this PTEN retrieve info as you
can see here between retrieve the info and I have EDT value this is for getting text.
This is for actually receiving Teske text from the user.
And then put that text inside another file in SD card which claim I'm going to show you in a minute
and you have TXI the value for actually getting those actually those inputs when the user actually put
some text inside the editor.
And then we build we want to actually retrieve those information.
So if you want to put more information inside these TXI the value takes you.
And we have EMG anemone as you can see here.
We have BT and allow access pictures here we want to actually access the pictures inside the SD card
and then don't look at those pictures inside these image switcher.
So that's why I actually created these objects linearly out horizontally so linearly or horizontal is
actually inside and they're actually horizontal scroll view.
OK.
And I have this image switcher for showing for showing the images then they use it or clicking on those
images inside the city nearly what is on top.
So now I'm going actually putting some more lines of code here and then I'm going explain to you what's
going on here.
So as you can see here these are the lines of code that I actually pasted here.
And as you can see I am actually making these buttons that are inside these linearly and vertical these
buttons for example.
These Downloads folder.
This immunity for the.
And other buttons.
A listener to the clicks of the user.
OK.
So for example between downloads for that certain click listener and here we need to actually passing
the context.
So main activity that this BTA and music for that certain click us and our main activity that is I have
these PTEN documents folders that are set and click and listener main activity that this PTEN ringtones
for their thoughts Stankovic listener main activity that this.
And we have these bits and podcasts folder between movies folder PTEN alarms folder PTEN pictures folder
BTA and save five PTEN retrieve info.
And I enjoy that so then click listen and an activity that does this.
But here we need to actually implement this article class and an interface for these buttons.
So here after this act of compact activity here I just need to type in implements of view dot unclick
listener so I have this view that actually exist in an interface.
And here I just need to press Enter key on my keyboard and now I am actually implementing this Archilochus
in our interface.
And if I hover over this error area it says class main activity must either be declared abstract or
implement abstract Smurfette unclick viewed as you can see we have our own view of you as an argument
of this uncle Mefford in uncock listener.
OK so Uncle Eagleson an uncle listener is actually an interface that we need to actually implement the
abstract Mefford unclick you uncle if you insight this interface.
So here after the Indian curly brace of the is uncreate Mefford here I can't just type in uncreate on
click.
I can just for example delete this method here and here again just insight is our main activity class.
And after the Hadian curly brace of this uncreate method I can just throw eclectically here and then
click can generate.
And then here click can implement Moffats and here as you can see I have this android dot view to view
that unclick listener interface as you can see here.
And inside that interface here we need to actually implement this method.
So here I just need to click on OK and now it's going to implement that Mefford for me.
OK.
And then here again just putting my own quotes that would be related to these buttons.
So now as you may know in Android because we want to actually access the SD card and read or write for
example some data on the SD card we need to actually first of all specify that we need to access the
SD SD card in Android manifest.
So after the Indian attack of this application tag as you can see here inside the manifest tank here
I need to actually specify that or you want to access the SD card.
So I just need to open a task here and then here I can just type in users permission and inside these
double codes.
I need to actually specify that what kind.
What kind of features in Android.
I meant to access.
So here I want to actually read and write some data from the SD card.
OK.
So first for software for the first permission here I'm going to just type in read as you can see hear
read and here is going to get you to show me some recommendations.
And here I can choose read external storage as you can see here.
Now here I can just close this tag here and here we need to actually use another repair mission.
So here I just need to open this tag.
Uses permission here.
I want to actually specify that I want to write an SD card.
OK.
So here I can just type in right and here it's going to actually give me some options as you can see
here.
Right.
Store right.
External storage.
So choose this option.
And then a person entered key on your keyboard.
So now I need to actually close the stack and now as you can see we can actually access the SD card
but not yet here inside this main activity that a file we need to actually put in some lines of code
regarding that we want to actually access the SD card and we need to actually get the user permission
for that.
OK.
So here we actually are putting some more lines of code.
And then I'm going to explain to you what's going on here.
So here first of all we need a constant.
For example our request called for actually using a permission in Android.
So here I'm going to paste this constant here public as you can see this is the constants that they
actually pasted here.
Public static.
So this constant is a static.
OK.
Final.
And as you can see this is constant.
It requires the code one to free forth.
OK so this is my request code for using the permission.
It doesn't make any difference what kind of numbers you use but I chose to use this one to free for
number.
OK.
And now I'm going to paste in some of it and then I'm going to explain to you what's going on here.
So as you can see here this is the method that they actually pasted inside these main activity class.
OK.
So the access modifier of this method is publish the return type of this method is boolean and the name
of this method is is stored as permission granted.
And here as you can see inside the body of the Smurfit I created an if statement so in Android in STK
version at when a free and above we need to actually specify that what kinds of permission we want to
use in Android and we need to actually get to get the permission of the user for using those features.
OK but before the SDK to be freed up we just needed to specify that that those permissions in Android
manifest but in SDK to any free and pop we need to specify it was permissions in in our Java codes too.
So that's why I created an if statement build that version is the it is greater than or equal to number
23.
Here I am specifying that if the STK version is 20 free or greater than 23 and here I created another
if statement if.
Check self permission.
So this is another method builtin in Android.
OK if takes self permission and that manifested permission right external storage.
OK.
Is equal to package manager that permission granted.
Ok so because you want to actually write and or read from the SD card if you actually have the permission
to write an external storage if you have the permission to read from the external external storage too.
OK.
So if checks have permission and troit that manifested permission write X then storage is equal to package
manager package manager that permission granted.
So if we have the permission to access the the external storage.
OK here I created a plug.
OK LUGG permission is granted.
Return true.
So if it is going to actually return TRUE else else as you can see I have an else statement here else
permission is revoked.
OK so we don't have the permission to actually access the external storage.
So here I just referred to this activity computer class we have this activity that the class as you
can see that request permissions.
So here we want to actually request the permissions in Android.
So this this is the context.
And here I have an object new string.
So if you have an object of actually an array of string objects.
OK.
And inside these are actually curly braces we need to specify what kind of actually the what kind of
permissions we want to use.
Ok manifest that permission right.
External storage.
And here we need to actually use or request code.
So here use this number one as you can see here and then I return false.
So this method is going to actually return false if we don't have any permission to access this.
For example Raghda external storage.
OK.
And here we have another statement.
So as you can see here if the STK version is actually less than number 23.
OK permission is granted permission is automatically granted on STK less than number 23 upon installation.
OK.
Permission is granted return true.
So this it is going I should return true.
OK so now we need to actually override another builtin method in Android.
And and here I'm going to pasting that method here.
So as you can see here this is the builtin method that I actually pasted here on request permission
result.
So whenever you use that for example gives me an operation to use some features in Android D-SLR if
it is going to be called.
OK so this least fit as you can see our accepts some arguments.
The first argument is request code.
The second argument is permissions as you can see here we have an array of permissions and we have Grantley's
results which is of type integer arii.
OK.
And here it called the superclass version of this method superdad and request the permission result
request code permissions Granth results.
And here I created an if statement if Granth results.
Sub-Zero.
OK.
So if for example if the permission in index zero of this Granth results.
So if you have these permissions for this permission write extension storage is going to be at index
0 of this Granth results rate is equal to package manager package manager that permission granted.
So if we can X access for example that the external storage and right on the card if that permission
is granted to us.
OK so is it this expression is going to be true if the permission is granted to us.
Now it's created a large LUGG permission plus permissions.
Sub-Zero was Granth results.
OK.
Sub-Zero so Granth results for example their results for actually giving us permission to use that feature
in Android.
OK so we need to override this method here.
OK.
And now inside is uncreate Smurfette.
I'm going to actually writing MF it actually referred to this is stored is stored is permission granted
here Ivan actually referred to dismember inside this uncreate Smurfit in order to show the user a message
whether we can actually access the external storage or not.
OK so here I can just type in.
It is stored as storage permission granted semicolon.
OK and now let's actually run our project and see what happens.
So now as you can see here our application is actually running on this emulator and that device actually
the application automatically.
And now he's showing me this message.
Allow app for free to access photos media and files on your device.
So if I click on deny or I'm not allowed to access the SD card OK and if I click on allow I am allowed
to access the SD card and write some data or it's Sunday to or from the SD card.
OK.
So this actually can deny.
And now I don't have the permission to access any directory or files or photos in SD card.
So let me actually click on this batch button here and now let me actually go to the background apps.
So here this app is actually in the background.
But this app this app is actually destroyed because I clicked I clicked on this back button in the undestroyed
my father is actually current.
So if I actually click on this app here again at the uncreate my fate is going to be called again.
So now as you can see again it's showing us this message allow app 83 to access photos media and files
and files on your device.
So here we have another option.
Never asked again.
So if I check this option and then click on D-NY it's not going to show me this message again.
And the user has to actually allow the permissions that this app needs in the settings app.
In the Android device.
OK.
So if we actually check this option and now at this time I want to allow the user to access.
For example allow the app to access the files in the SD card.
OK.
So let me actually click on now.
And now I am allowed to access the files in SD card.
OK so let me actually click on the spot button again and here again we actually open this up here and
now it's not going to show me that message again.
OK so here I am allowed to access the files in SD card and that's because of these methods that they
actually put here in site of this class.
OK.
So here instead of just using this number of one I could just use these are requests that constant that
they actually put here.
OK.
I created this constant here in order to show you that if you want to actually use other permissions
other than this right external storage in Android here if you want to use other commissions you need
to actually to use other request codes for those permissions.
OK.
So I created this up request court for showing you that.
But here I just preferred to use this number one here.
OK.
So hopefully that makes sense.