This tutorial series will guide you through building a simple Android File Explorer application in Kotlin. You will develop a file explorer application with core functionalities of creating, deleting, copying and moving files/folders. I assume that you have a good understanding of Android Development and Kotlin language. These tutorials are not meant to teach you Kotlin or Android. Think of this series as practicing/refreshing your Kotlin/Android skills. We will not be focusing on making the best file explorer application or the best architecture application ever! As I said this series is meant for practicing and refreshing your skills.
Brief breakdown of upcoming tutorials
I have divided this series in segments of short to medium sized tutorials. In this tutorial we will be setting up our project. In next tutorial you will build the core part of the application which is browsing through the file system structure. Then you will follow up by adding breadcrumbs to provide navigation to any point previously opened in the file structure. After that you will add feature to create/delete files and folders. Followed by that you will add options to copy and move files from one directory to another. Finally we will end the series with a tutorial on miscellaneous stuff!
Throughout the tutorial I will not be providing the complete code, as I expect you have a fair knowledge of Android Development, code that is too verbose will not be shown. The complete code for the project we are building is available on this GitHub repo. I recommend that you download the complete project, in case you get stuck at any point, you can refer the completed project.
Setting up the project
Make sure you have the latest Android Studio version installed. Open it and create a new project, make sure to turn on Kotlin support.
Once the project is created, add the permission for accessing external storage.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
As of Android 6.0, permissions have to be request from the user at runtime, you will do that in the next tutorial.
Add a FileProvider
From Android 7.0 your app is not allowed to share a ‘file:///’ URI with an Intent, we would require that to open files when when the user taps on them. We can fix this behaviour by proving a FileProvider and then getting a shareable Uri for our ‘file:///’ path. Right now you will just set up the file provider, you will use it to launch intents in next tutorial.
Note: FileProvider was introduced for secure sharing of files across applications. if you want to learn more read the official doc on FileProvider.
Go ahead and create a class named GenericFileProvider which extends FileProvider.
class GenericFileProvider: FileProvider()
Create a file in the xml directory named provider_paths.xml.
Register GenericFileProvider in manifest.
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
That is it for the setup, next you will dive deep into the code.
Screenshots of Completed Kotlin application
Here is a small tutorial series on Kotlin language.