Login     Sign Up
Tugadar (@admin)
17 days ago

The Android Media Store provides a managed repository for audio, video, and image files. Whenever you add a new multimedia file to the Android filesystem, it should be added to the Media Store to expose it to other applications.

The MediaStore class includes a number of convenience methods to simplify inserting files into the Media Store. For example, the following code snippet shows how to insert an image directly into the Media Store:





“Photo of my cat!”);

Using the Contacts Provider

Access to the Contact Manager is particularly powerful on a communications device. Android does the right thing by exposing all the information available from the contacts database to any application granted the READ_CONTACTS permission.

In the following example, an Activity gets a Cursor to every person in the contact database, creating an array of Strings that holds each contact’s name and phone number.

To simplify extracting the data from the Cursor, Android supplies public static properties on the People class that expose the column names.

// Get a cursor over every contact.

Cursor cursor = getContentResolver().query(People.CONTENT_URI, null, null, null, null);

Let the activity manage the cursor lifecycle. startManagingCursor(cursor);

Use the convenience properties to get the index of the columns

int nameIdx = cursor.getColumnIndexOrThrow(People.NAME);
int phoneIdx = cursor. getColumnIndexOrThrow(People.NUMBER);

String[] result = new String[cursor.getCount()]; if (cursor.moveToFirst())

do {

// Extract the name.

String name = cursor.getString(nameIdx);

// Extract the phone number.

String phone = cursor.getString(phoneIdx); result[cursor.getPosition()] = name + “ (“ + phone + “)”;

} while(cursor.moveToNext());

To run this code snippet, you need to add the READ_CONTACTS permission to your application.

As well as querying the contacts database, you can use this Content Provider to modify, delete, or insert contact records.