Content provider is a way for different apps to share information with each other. It's like having a big library where different apps can store their information, and other apps can come to the library to read or write that information.

For example, imagine you have a photo editing app that stores all the photos you edit, and you want to share those photos with a social media app. Instead of copying the photos from one app to the other, you can use a content provider to share the photos directly between the apps. The photo editing app would store the photos in its content provider, and the social media app would access the photos through the content provider.

To access data from a content provider, you use a ContentResolver object that communicates with the provider using a content URI. A content URI is a string that identifies the data you want to access, such as content://com.example.app.provider/table1.

To create your own content provider, you need to implement a subclass of ContentProvider and declare it in your manifest file. You also need to implement methods for querying, inserting, updating, and deleting data in your provider.

<aside> 💡 Each content URI must be unique. For this reason developers usually use their package name

</aside>

<aside> 💡 In reverse engineering prospective, it’s a good idea to search for content:// to find app content providers.

</aside>

Each content URI consist of three parts. For example content://com.android.contacts/contacts :

Untitled

Playing With Content Providers

How to access them with adb?

content query --uri content://com.android.contacts/contacts/1

How to create a content provider?

Here's a basic example of how to create a content provider in Android:

First, define the contract for your content provider in a Java interface:

public interface MyProviderContract {
    String AUTHORITY = "com.example.myapp.provider";
    Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/items");
    String COLUMN_ID = "_id";
    String COLUMN_NAME = "name";
    String COLUMN_DESCRIPTION = "description";
}

This interface defines the authority for your content provider (AUTHORITY), the content URI for your provider (CONTENT_URI), and the column names for the data you want to expose (COLUMN_ID, COLUMN_NAME, and COLUMN_DESCRIPTION).