欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

MediaStore的应用,MediaStore应用,MediaStore.A

来源: javaer 分享于  点击 17319 次 点评:44

MediaStore的应用,MediaStore应用,MediaStore.A


MediaStore.Audio: 存放音频信息

MediaStore.Image: 存放图片信息

MediaStore.Vedio: 存放视频信息

这三个内部类存储了多媒体的一些基本信息,并通过ContentProvider的数据共享的机制,将其共享出来,提供给各个应用程序使用。下面的例子展示了一个读取图片信息的示例:

参考:http://www.cnblogs.com/wisekingokok/archive/2011/09/20/2182272.html

public class MainActivity extends Activity {     private ImageView image;     private Button btn;     private int index;     private int totalCount;     private ArrayList<String> imageSrcs = new ArrayList<String>();     @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);         image = (ImageView)findViewById(R.id.image);         btn = (Button)findViewById(R.id.btn);         //获取上下文         Context ctx = MainActivity.this;         //获取ContentResolver对象         ContentResolver resolver = ctx.getContentResolver();         //获得外部存储卡上的图片缩略图         Cursor c = resolver.query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, null, null, null, null);         //为了for循环性能优化,用一变量存储数据条数         totalCount = c.getCount();         //将Cursor移动到第一位         c.moveToFirst();         //将缩略图数据添加到ArrayList中         for(int i=0; i<totalCount; i++){             int index = c.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA);             String src = c.getString(index);             imageSrcs.add(src);             index = i;             c.moveToNext();         }         //关闭游标         c.close();         //点击按钮,切换图片         btn.setOnClickListener(new OnClickListener(){             @Override             public void onClick(View v) {                 String src = imageSrcs.get(index);                 image.setImageURI(Uri.parse(src));                 index ++;                 if(index == totalCount){                     index = 0;                 }             }         });     } }//该片段来自于http://byrx.net
相关栏目:

用户点评