Custom content providers in android
2 answers
In addition to the extensive developer guide section on content providers , you can check out the Notepad Tutorial and Note Pad Sample Code for information on creating your own content providers.
+4
a source to share
In the manifest of the application providing the content you would have:
<provider android:name="Inventory" android:authorities="com.package.name.Inventory" />
And in the application receiving the content
String inventoryItem = "dunno";
try {
Uri getItem = Uri.parse(
"content://com.package.name.Inventory/database_items");
String[] projection = new String[] { "text" };
Cursor cursor = managedQuery(getItem, projection, null, null, null);
if (null != cursor && cursor.moveToNext()) {
int index = cursor.getColumnIndex("text");
inventoryItem = cursor.getString(index));
}
cursor.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
In an external program, this will return the item specified by item_socks, but this is just a general example of having only one item specified by that name. You will be querying a database table named database_items that looks something like this:
id | name | text
1 | item_socks | brown couple red stripe
inventoryItem will then be equal to "brown pair red stripe"
0
a source to share