Learn how to use “FileProvider” in Android

Share file with FileProvider in Android, Learn how to use FileProvider in Android


FileProvider is part of AndroidXCoreLibrary.  FileProvider handles file sharing from one app to another app. FileProvider component generates content URIs for files based on declaration in xml file. Here we will see how to add FileProvider in app.

Create File Paths

Create a new file in res/xml folder with name filepaths.xml. We need to specify directories used by our app in the file by xml element. Here is sample code for the filepaths:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="">
       <external-path name="external_files" path="."/>

Within paths tag we can use <file-paths>, <external-path> and other tags to define paths for each type of directory and file.


Shares directory within the files/ directory of the app’s internal storage


Shares directories in external storage


element to share directories in your internal cache directory

Specify FileProvider

We have defined how our internal and external storage directories will look like, now we can define our FileProvider with paths within the Manifest.xml file.

<manifest xmlns:android=""
android:resource="@xml/filepaths" />

Let’s understood properties of provider


This attribute specifies the URI authority that you want to use for content URIs granted by the FileProvider. Generally value for this attribute is APP_PACKAGE_NAME + . + fileprovider


This element specifies paths which we create in our last step.

We are ready to test app now. We can define path for each type of directory.

Hope you have gain some knowledge. 

Let me know you feedback.

You can also request my new demo for any topic, I will be happy to provide it.

Thank you.

Share this content:


More Posts

Introduction to Kotlin: A Versatile and Modern Programming Language

Kotlin, a versatile and modern programming language, offers developers a concise, safe, and interoperable coding experience. With features like null safety, extension functions, and coroutines, Kotlin enhances productivity and readability, making it an attractive choice for Android development and beyond. Whether you’re new to programming or an experienced developer, exploring Kotlin opens up a world of possibilities for building robust and expressive applications.

Mastering the Android Activity Lifecycle: A Comprehensive Guide

The Android Activity Lifecycle is a fundamental concept for Android developers. It defines how an Activity behaves during its lifecycle, from creation to destruction. Understanding the Activity Lifecycle is crucial for managing resources efficiently and delivering a smooth user experience. In this blog post, we’ll briefly introduce the different states an Activity can be in and the main callback methods associated with each state. Let’s dive in and explore this important aspect of Android app development!

Table of Contents

Send Us A Message