Use ContentProvider to manage multimedia-----View all pictures in multimedia data

Source: Internet
Author: User

Import java.util.ArrayList;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;

Import Android.os.Bundle;
Import Android.provider.MediaStore.Images.Media;
Import android.app.Activity;
Import Android.database.Cursor;
Import Android.view.Menu;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.ListView;
Import Android.widget.SimpleAdapter;

Binding listeners for the View button's Click event
View.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View v) {
Empty the original data in names, Descs, filenames collection
Names.clear ();
Descs.clear ();
Filenames.clear ();
Search all picture information by Contentresolver
cursor cursor = getcontentresolver (). Query (
Media.external_content_uri, NULL, NULL, NULL, or NULL);
while (Cursor.movetonext ()) {
Get the display name of a picture
String name = cursor.getstring (Cursor.getcolumnindex (media.display_name));
Get a detailed description of the picture
String desc = cursor.getstring (Cursor.getcolumnindex (media.description));
Get the data where the picture is saved
byte[] data = Cursor.getblob (Cursor.getcolumnindex (media.data));
Add a picture name to the Names collection
Names.add (name);
Add a picture description to the Descs collection
Descs.add (DESC);
Add a picture save path to the Filenames collection
Filenames.add (new String (data, 0, data.length-1));
}
Create a list collection with the elements of the list set as map
list<map<string, string>> listItems = new arraylist<map<string,string>> ();
Converts data from a names, Descs, two collection object into the Map collection
for (int i = 0; I<names.size (); i++) {
map<string, object> listItem = new hashmap<string, object> ();
Listitem.put ("Name", Names.get (i));
Listitem.put ("desc", Descs.get (i));
Listitems.addall (ListItems);
}
Create a Simpleadapter
Simpleadapter simpleadapter = new Simpleadapter (
Mainactivity.this, ListItems, R.layout.line,
New string[]{"name", "Desc"}, new Int[]{r.id.name,r.id.desc});
Set adapter for the show ListView component
Show.setadapter (Simpleadapter);
}
});

Use ContentProvider to manage multimedia-----View all pictures in multimedia data

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.