managedQuery (
Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
This method was
deprecated in API level 11.
Use CursorLoader instead.
Wrapper around
query(android.net.Uri, String[], String, String[], String) that gives the resulting Cursor to call
startManagingCursor(Cursor) so that the activity will manage its lifecycle for you. If you are targeting
HONEYCOMB(API 11) or later, consider instead using
LoaderManager instead, available via
getLoaderManager().
Warning: Do not call
close() on a cursor obtained using this method, because the activity will do that for you at the appropriate time. However, if you call
stopManagingCursor(Cursor) on a cursor from a managed query, the system will not automatically close the cursor and, in that case, you must call
close().
Parameters
uri - The URI of the content provider to query.
projection - List of columns to return.
selection - SQL WHERE clause.
selectionArgs - The arguments to selection, if any ?s are present
sortOrder - SQL ORDER BY clause.
Returns: The Cursor that was returned by query().
1.
Declare a Cursor.
2. In the MainActivity.java file, add the line below to the imports section. This is only needed in this example because we are using this as our URI.
import android.provider.MediaStore.Audio;
3.
Declare and Define a String Array named
myStringArray set to
{ "*" }.
4. In the MainActivity.java file, add the following line of code. This example sets
the Cursor named myCursor with query results from
a URI of
android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
a list of all columns by using
myStringArray,
a selection of
android.provider.MediaStore.Audio.Media.IS_MUSIC + "!=0",
with the selection arguments and sort order both set to
null.
myCursor = managedQuery(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, myStringArray, android.provider.MediaStore.Audio.Media.IS_MUSIC + " != 0", null, null);
5. Compile and run!
Resources:
http://developer.android.com/reference/android/app/Activity.html#managedQuery(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String)