Introduction

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.

kotlin

Once the project is created, add the permission for accessing 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.

Create a file in the xml directory named provider_paths.xml.

Register GenericFileProvider in manifest.

That is it for the setup, next you will dive deep into the code.

Screenshots of Completed Kotlin application

kotlin

kotlin

kotlin

kotlin


Here is a small tutorial series on Kotlin language.

Getting Started With Kotlin.


Gurleen Sethi

How can I tell you about myself in just a few lines, to get to know me you can reach out to me, email, text, call, or any other method of communication you like. I am always there for you!

1 Comment

Build a File Explorer in Kotlin – Part 2 – Reading files from paths - TheTechnoCafe · August 12, 2018 at 8:31 am

[…] So now that you have set up the project, lets start coding and making this File Explorer come to life! (If you haven’t read the first part of this series, please read it here.) […]

Leave a Reply

Your email address will not be published. Required fields are marked *

sixteen − 7 =