Get a list of available Content Providers
Asked Answered
H

6

41

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.

Hardan answered 4/1, 2010 at 19:29 Comment(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...Teatime
possible duplicate of Android Content provider listPapyrology
P
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);
        }
    }
}
Piercing answered 4/1, 2010 at 19:54 Comment(4)
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?Pul
@Pul No you never know it until you they release their application's secrete :)Siobhan
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 #28040945 )Thornberry
Look at this now (#28040945)Antilepton
E
24

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.

Eighteenmo answered 29/5, 2013 at 0:18 Comment(1)
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.Lapides
H
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.

Hereditament answered 15/1, 2011 at 8:4 Comment(0)
D
12

The list of registered content providers can be gathered with:

adb shell dumpsys package providers

Tested on Android 8.1 Oreo

Discuss answered 7/11, 2019 at 13:51 Comment(0)
P
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.

Pokeweed answered 14/3, 2011 at 18:15 Comment(0)
B
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;
Bookkeeping answered 5/2, 2015 at 6:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.