40

Is there a way to programmatically list all available content providers on a device? No real use case, I just thought it might be neat to see what apps I have installed on my phone that have exposed content providers.

Mark B
  • 183,023
  • 24
  • 297
  • 295
  • 2
    You can run `adb bugreport` from the command line which will dump a *ton* of info about the active device, including loads of information about each package and everything they provide: activities, services, content providers... – Christopher Orr Jan 05 '10 at 04:08
  • possible duplicate of [Android Content provider list](http://stackoverflow.com/questions/1187541/android-content-provider-list) – richq Jan 15 '11 at 10:01

6 Answers6

58

It should be possible by calling PackageManager.getInstalledPackages() with GET_PROVIDERS.

EDIT: example:

for (PackageInfo pack : getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS)) {
    ProviderInfo[] providers = pack.providers;
    if (providers != null) {
        for (ProviderInfo provider : providers) {
            Log.d("Example", "provider: " + provider.authority);
        }
    }
}
medavox
  • 175
  • 2
  • 11
Mirko N.
  • 10,537
  • 6
  • 38
  • 37
  • 3
    I was able to print out a list of providers, but how can I determine the actual content that can be queried? Does ProviderInfo contain the URI I can pass into a query() call? – gonzobrains May 15 '13 at 23:23
  • @gonzobrains No you never know it until you they release their application's secrete :) – dharmendra Apr 21 '14 at 13:37
  • 1
    I am looking for Bookmarks URI for a given device. I can't find content://browser/bookmarks uri using your code? any idea on how to find the right Bookmark uir? (see my question http://stackoverflow.com/questions/28040445/android-browser-bookmarks-uri-does-not-work-on-all-device-how-to-find-out-the-c ) – Pascal Jan 20 '15 at 13:16
  • Look at this now (http://stackoverflow.com/questions/28040445/android-browser-bookmarks-uri-does-not-work-on-all-devices-how-to-find-out-the/28403816#28403816) – Dhiraj Himani Feb 09 '15 at 06:14
23

From the command line, run:

adb shell dumpsys | grep Provider{

Note the opening brace. This will give you a short list of all the providers installed through various packages.

Simon Guest
  • 2,112
  • 1
  • 15
  • 21
  • I believe the actual line matched by this grep command shows the package of the app and the package of the provider. If you want to see the authority associated with it, it's on the previous line inside square brackets. You'll likely want to dump it to a file and look at it with context. – rmeador Nov 25 '19 at 19:29
14

I used adb shell command like this $ adb shell dumpsys > dumpsys.txt and search for content providers string in the output file. From that i can see the list of content providers in the device/emulator.

Vikas Patidar
  • 42,865
  • 22
  • 93
  • 106
Tuyen Dinh
  • 465
  • 5
  • 11
10

The list of registered content providers can be gathered with:

adb shell dumpsys package providers

Tested on Android 8.1 Oreo

Yom
  • 366
  • 3
  • 6
9
List<ProviderInfo> providers = getContext().getPackageManager()
    .queryContentProviders(null, 0, 0);

lists all content providers available to you on this device.

Or, if you know the process name and UID of the provider, you can reduce the list by specifying those two parameters. I have used this before to check the existence of my own content providers, more specifically those of previous (free vs. paid) installations:

List<ProviderInfo> providers = getContext().getPackageManager()
    .queryContentProviders("com.mypackage", Process.myUid(), 0);

Note the android.os.Process.myUid() to get my own process's user ID.

Cornel Masson
  • 1,352
  • 2
  • 17
  • 33
1
List<ProviderInfo> returnList = new ArrayList<ProvderInfo>();
   for (PackageInfo pack:getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS)) 
   {
    ProviderInfo[] providers = pack.providers;
   if (providers != null) 
   { 
      returnList.addAll(Arrays.asList(providers)); 
   } 
 } 
 return returnList;
Code Lღver
  • 15,573
  • 16
  • 56
  • 75
manDroid
  • 1,125
  • 3
  • 13
  • 25