Mediastore and Media.external_content_uri

Source: Internet
Author: User

Mediastore This class is a multimedia database provided by the Android system, which can be extracted from the Android multimedia information.

This mediastore includes all the information of the multimedia database, including audio, video and images, and Android encapsulates all of the multimedia database interfaces, all of which are not created by themselves. Direct calls take advantage of Contentresolver to eliminate the use of those encapsulated interfaces to perform database operations.

Today I'll introduce some of these interfaces to use.

First, to get a contentresolver instance, as follows:

contentresolver mresolver = ctx. getcontentresolver ();

The top of the ctx is a context,activity.this is that context, this context is equivalent to a contextual environment. Once you get this context, you can call the Getcontentresolver interface to get the contentresolver instance.

Contentresolver instances obtained, you can make a variety of queries, the following I take the audio database as an example to explain the method of adding and deleting, video and image and audio very similar.

Before explaining the various queries, I'll show you how to see which multimedia tables are available on Android. In Adbshell, locate the/data/data/com.android.providers.media/databases/, and then locate the SD card database file (typically a. db file), Then enter the command sqlite3 with the name of the database to query the Android multimedia database. The table command lists all the multimedia database tables, and the. Scheme plus the table name can query all column names in the table. Here you can use the SQL statement to see the data you want, and remember to keep in mind that each statement is followed by a semicolon. Here's how to add and revise these tables.

Query, the code looks like this:

cursor cursor = resolver.query (_uri, prjsselectionsselectargsorder);

The

Contentresolver Query method accepts several parameters with the following parameters:
    Uri : This URI represents the database name + table name to query. This URI is generally obtained directly from the Mediastore, for example, I want to fetch all the information of the song, I must use mediastore.audio.media. External_content_uri this URI. Album information to use  mediastore.audio.albums.external_content_uri this URI to query, and other queries are similar.

    Prjs : This parameter represents the to be selected from the table, represented by a string array.
    selections : equivalent to the in SQL statement Span style= "COLOR: #ff6600" >where clause , which represents your query criteria .
    Selectargs : Does this argument mean that you have a selections? This symbol is where the actual value can be substituted for this question mark. What if selections this? , then this string array can be null.
     order : Describes what the query results are sorted by.


Above is the meaning of each parameter, it returns the query results a cursor, the cursor is equivalent to the database query result, usage and it is similar.
--------------------------------------------------------------------------------------------------------------- ----
Add the code as follows:

1 contentvalues Values New  contentvalues (); 2 values.put (mediastore.audio.playlists.members.play_order,0); 3 values);

    This insert passes only two parameters, one is the URI (the same URI as the query), and the other is contentvalues. This contentvaluses corresponds to a row of data in the database , as long as the put method to set each column, the direct use of the Insert method to insert is good.
    Update, code as follows:
    

1 Contentresolver resolver = ctx.  Getcontentresolver (); 2 uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; 3 New contentvalues (); 4 values.put (MediaStore.Audio.Media.DATE_MODIFIED, sid); 5 resolver.update (Mediastore.audio.playlists.external_content_uri,values, where, Selectionargs);

The above Update method and query also has an increase in the parameters are very similar, here will not repeat the narrative, you can also directly refer to Google's documentation, there is also written clearly.

Delete the code as follows:

1 contentresolver resolver = ctx.getcontentresolver (); 2 resolver.delete (Mediastore.audio.playlists.external_content_uri,where, Selectionargs);

The delete and update method is very similar, you can see the Update method immediately will understand.

Reprint to http://blog.csdn.net/jdsjlzx/article/details/9080235

Mediastore and Media.external_content_uri

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.