Get a list of available Content Providers
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);
}
}
}
Android Content provider list
The publicly available ones are listed in the android.provider package in the SDK documentation:
http://developer.android.com/reference/android/provider/package-summary.html
All other ones are undocumented, presumably for a reason. You are welcome to search the Android source code for those classes which extend ContentProvider
, perhaps using Google Code Search. And, if you are working on improving the Android firmware, you can also make inquiries on one of the Android open source project lists to see how best for you to add in your specific desired capability.
How to get list of content providers for all users on a tablet
After researching and trying out all possible options (including reference in this post), I figured out that its not possible to write a Content Provider which can share data across multiple users and restricted profiles on a tablet
Get list of all names in content provider
I think this would help you
ArrayList<String> nameList = new ArrayList<String>();
String[] projection = {"name"};
String selection = null;
String[] selectionArgs = null;
String sort = null;
resolver = getContentResolver();
cursor = resolver.query(uri, projection, selection, selectionArgs, sort);
Log.i("TUTORIAL", "counts :"+cursor.getCount());
String s;
if(cursor.moveToFirst()) {
do {
nameList.add(cursor.getString(0));
//your code
//s = cursor.getString(x);
Log.i("TUTORIAL", ""+cursor.getString(0));
}while(cursor.moveToNext());
}
Accessing data from Custom Content Providers
You can not initialize the content provider from somewhere else in your code like this, as the ContentProvider might be the first (or only) component of your app that's instantiated.
However, you can read the authority dynamically from the Manifest or a String resource. In my answer on Does Android Content Provider authority definition break the DRY rule? I outlined how we that in our OpenTasks-Provider.
How can I get every row from a Content Provider?
You are getting "rows-1" because your use of moveToFirst()
followed by moveToNext()
as the loop control causes you to skip the first row.
If you are seeing all rows of the DB with the same value for column "string", there is either a problem with the code that shows you "s" (which you didn't post) or your DB contains the same value for every row, or you have not implemented query()
correctly in your ContentProvider
.
You can also use Cursor.getCount() to get the number of rows in the cursor.
This code works for me when run against a content provider backed by a DB:
Cursor c = getContentResolver().query(uri, null, null, null, null);
if (c != null) {
while (c.moveToNext()) {
String s = c.getString(c.getColumnIndexOrThrow("name"));
Log.i("Demo", s);
}
c.close();
}
Query Android content provider from command line (adb shell)
There is a content
command:
usage: adb shell content [subcommand] [options]
usage: adb shell content insert --uri <URI> [--user <USER_ID>] --bind <BINDING> [--bind <BINDING>...]
<URI> a content provider URI.
<BINDING> binds a typed value to a column and is formatted:
<COLUMN_NAME>:<TYPE>:<COLUMN_VALUE> where:
<TYPE> specifies data type such as:
b - boolean, s - string, i - integer, l - long, f - float, d - double
Note: Omit the value for passing an empty string, e.g column:s:
Example:
# Add "new_setting" secure setting with value "new_value".
adb shell content insert --uri content://settings/secure --bind name:s:new_setting --bind value:s:new_value
usage: adb shell content update --uri <URI> [--user <USER_ID>] [--where <WHERE>]
<WHERE> is a SQL style where clause in quotes (You have to escape single quotes - see example below).
Example:
# Change "new_setting" secure setting to "newer_value".
adb shell content update --uri content://settings/secure --bind value:s:newer_value --where "name='new_setting'"
usage: adb shell content delete --uri <URI> [--user <USER_ID>] --bind <BINDING> [--bind <BINDING>...] [--where <WHERE>]
Example:
# Remove "new_setting" secure setting.
adb shell content delete --uri content://settings/secure --where "name='new_setting'"
usage: adb shell content query --uri <URI> [--user <USER_ID>] [--projection <PROJECTION>] [--where <WHERE>] [--sort <SORT_ORDER>]
<PROJECTION> is a list of colon separated column names and is formatted:
<COLUMN_NAME>[:<COLUMN_NAME>...]
<SORT_ORDER> is the order in which rows in the result should be sorted.
Example:
# Select "name" and "value" columns from secure settings where "name" is equal to "new_setting" and sort the result by name in ascending order.
adb shell content query --uri content://settings/secure --projection name:value --where "name='new_setting'" --sort "name ASC"
usage: adb shell content call --uri <URI> --method <METHOD> [--arg <ARG>]
[--extra <BINDING> ...]
<METHOD> is the name of a provider-defined method
<ARG> is an optional string argument
<BINDING> is like --bind above, typed data of the form <KEY>:{b,s,i,l,f,d}:<VAL>
android content provider AUTHORITIES
The Authority is used to interact with a particular content provider, that means it must be unique. That's why is a good practice to declare it as your domain name (in reverse) plus the name of the package containing the provider, that way is less likely that other developer creates an app with a content provider declaring the same authority.
You declare it in the manifest so your app and other apps (if you let them) can manipulate
data through your content provider in the form of a uri:
content://authority-name/data-in-the-provider
It works similar to domains in http urls:
http://domain-name/data-in-the-site
Related Topics
Android Opengl .Obj File Loader
What Is the Meaning of Android.Intent.Action.Main
How to Set Custom Typeface to Items in Navigationview
Android Sharedpreferences in Fragment
Debugging with Android Studio Stuck at "Waiting for Debugger" Forever
API to Automatically Upload APK to Google Play
Finding the Dominant Color of an Image in an Android @Drawable
Android Multiple Screen Sizes with Same Density
Custom Global Application Class Breaks with "Android.App.Application Cannot Be Cast To"
Cordova Platform Add Android Not Working While Listing Android Targets
Recompile with -Xlint in Android Studio
Support Library Vectordrawable Resources$Notfoundexception
There Is No Debug.Keystore in .Android Folder
Add 'Tools:Replace="Android:Value"' to <Meta-Data> Element at Androidmanifest
How to Work with Android's In-App Update API
How to Get Email Id from Facebook Sdk in Android Applications