import java.io.IOException;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.media.ExifInterface;
import android.os.Bundle;
import android.provider.MediaStore;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//测试1
//getVideosInfo();
//测试2
//getPhotosInfo();
//测试3
getAudiosInfo();
} //获取设备上所有的视频信息
private void getVideosInfo() {
ContentResolver contentResolver=getContentResolver();
String [] videoColumns=new String[]{
MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATA,
MediaStore.Video.Media.TITLE,
MediaStore.Video.Media.MIME_TYPE
};
// 两种方法均可
// Cursor cursor=
// this.managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, mediaColumns, null, null, null);
Cursor cursor=contentResolver.query
(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoColumns, null, null, null);
while (cursor.moveToNext()) {
String _id=
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));
String filePath=
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
String title=
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));
String mime_type=
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));
System.out.println("_id="+_id);
System.out.println("title="+title);
System.out.println("filePath="+filePath);
System.out.println("mime_type="+mime_type);
}
} //获取设备上所有的照片信息
private void getPhotosInfo() {
ContentResolver contentResolver=getContentResolver();
String [] photoColumns=new String[]{
MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA,
MediaStore.Images.Media.TITLE,
MediaStore.Images.Media.MIME_TYPE,
MediaStore.Images.Media.SIZE,
MediaStore.Images.Media.ORIENTATION
};
// 两种方法均可
// Cursor cursor=
// this.managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, mediaColumns, null, null, null);
Cursor cursor=contentResolver.query
(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, photoColumns, null, null, null);
while (cursor.moveToNext()) {
String _id=
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID));
String filePath=
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
String title=
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.TITLE));
String mime_type=
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.MIME_TYPE));
String size=
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.SIZE));
//得到照片旋转角度方法一
String orientation0=cursor.getString
(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.ORIENTATION));
System.out.println("_id="+_id);
System.out.println("size="+size);
System.out.println("title="+title);
System.out.println("filePath="+filePath);
System.out.println("mime_type="+mime_type);
System.out.println("第一处 orientation0="+orientation0);
try {
ExifInterface exifInterface=new ExifInterface(filePath);
String image_length=
exifInterface.getAttribute(ExifInterface.TAG_IMAGE_LENGTH);
String image_width=
exifInterface.getAttribute(ExifInterface.TAG_IMAGE_WIDTH);
String orientation1=
exifInterface.getAttribute(ExifInterface.TAG_ORIENTATION);
String dateTime=
exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
System.out.println("image_length="+image_length);
System.out.println("image_width="+image_width);
System.out.println("dateTime="+dateTime);
//得到照片旋转角度方法二
//应该结合ExifInterface源码分析.
//此处有待于进一步分析和验证
switch (Integer.valueOf(orientation1)) {
case 1:
System.out.println("第二处旋转角度="+0);
break;
case 2:
//matrix.invert(matrix);
break;
case 3:
//matrix.setRotate(180);
System.out.println("第二处旋转角度="+180);
break;
case 4:
//matrix.invert(matrix);
//matrix.setRotate(180);
System.out.println("第二处旋转角度="+180);
break;
case 5:
//matrix.setRotate(90);
//matrix.invert(matrix);
System.out.println("第二处旋转角度="+90);
break;
case 6:
//matrix.setRotate(90);
System.out.println("第二处旋转角度="+90);
break;
case 7:
//matrix.invert(matrix);
//matrix.setRotate(90);
System.out.println("第二处旋转角度="+90);
break;
case 8:
//matrix.setRotate(270);
System.out.println("第二处旋转角度="+270);
break;
default:
break;
}
System.out.println("XXXXXXXXXXXXXXXXXXX");
} catch (IOException e) {
e.printStackTrace();
} } } //获取设备上所有的音频信息
private void getAudiosInfo() {
ContentResolver contentResolver=getContentResolver();
String [] audioColumns=new String[]{
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.MIME_TYPE
};
// 两种方法均可
// Cursor cursor=
// this.managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, mediaColumns, null, null, null);
Cursor cursor=contentResolver.query
(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, audioColumns, null, null, null);
while (cursor.moveToNext()) {
String _id=
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID));
String filePath=
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
String title=
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
String mime_type=
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE));
System.out.println("_id="+_id);
System.out.println("title="+title);
System.out.println("filePath="+filePath);
System.out.println("mime_type="+mime_type); } } }

移动开发:Android中MediaStore使用示例

												

Android 流媒体系列(二)的更多相关文章

  1. ANDROID Porting系列二、配置一个新产品

    ANDROID Porting系列二.配置一个新产品 详细说明 下面的步骤描述了如何配置新的移动设备和产品的makefile运行android. 1.         目录//vendor/创建一个公 ...

  2. Android画图系列(二)——自己定义View绘制基本图形

    这个系列主要是介绍下Android自己定义View和Android画图机制.自己能力有限.假设在介绍过程中有什么错误.欢迎指正 前言 在上一篇Android画图系列(一)--自己定义View基础中我们 ...

  3. Android学习系列(二)布局管理器之线性布局的3种实现方式

    转载请注明出处:http://blog.csdn.net/lhy_ycu/article/details/39643669 LinearLayout是Android控件中的线性布局控件,它包括的子控件 ...

  4. Android 流媒体系列(一)

    Android   设置铃声分析 代码其实没有几行,这里简单记录下学习的过程. Android系统启动时会扫描系统与SD卡中的对媒体文件,分别存入数据库sqlite中,以contentProvider ...

  5. Android自定义控件系列(二)—icon+文字的多种效果实现

    转载请注明出处:http://www.cnblogs.com/landptf/p/6290810.html 今天给大家带来一个很简单但是很常用的控件ButtonExtendM,在开发中我们经常会用到图 ...

  6. Android Studio系列教程二--基本设置与运行

    Android Studio系列教程二--基本设置与运行 2014 年 11 月 28 日 DevTools 本文为个人原创,欢迎转载,但请务必在明显位置注明出处! 上面一篇博客,介绍了Studio的 ...

  7. Android Camera系列开发 (二)通过Intent录制视频

    Android Camera系列开发 (二)通过Intent录制视频 作者:雨水  2013-8-18 CSDN博客:http://blog.csdn.net/gobitan/ 概述 使用Camera ...

  8. Android高效率编码-第三方SDK详解系列(二)——Bmob后端云开发,实现登录注册,更改资料,修改密码,邮箱验证,上传,下载,推送消息,缩略图加载等功能

    Android高效率编码-第三方SDK详解系列(二)--Bmob后端云开发,实现登录注册,更改资料,修改密码,邮箱验证,上传,下载,推送消息,缩略图加载等功能 我的本意是第二篇写Mob的shareSD ...

  9. Android流媒体开发之路二:NDK开发Android端RTMP直播推流程序

    NDK开发Android端RTMP直播推流程序 经过一番折腾,成功把RTMP直播推流代码,通过NDK交叉编译的方式,移植到了Android下,从而实现了Android端采集摄像头和麦克缝数据,然后进行 ...

随机推荐

  1. create mysql database

    CREATE DATABASE IF NOT EXISTS yourdbname DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

  2. jQuery 源码分析和使用心得 - core.js

    core是jQuery的核心内容, 包含了最基础的方法, 比如我们常用的 $(selector, context), 用于遍历操作的 each, map, eq, first 识别变量类型的 isAr ...

  3. [剖析Javascript原理]1.原生数据类型

    一.原生数据类型 JS共有5种原生数据类型: Boolean true或者false String 字符串,在单引号或者双引号之间(不存在字符类型) Number 整数或者浮点数 Null 空 und ...

  4. Eclipse 修改编码格式

    在Eclipse的开发使用中,我们经常使用的是UTF-8,但是刚刚安装的或者是导入的项目是其他编码的默认是GBK的,这就造成我们的项目乱码,一些中文解析无法查看,对我们的开发造成不便. 修改工作空间默 ...

  5. python递归函数下不能正常使用yield

    # -*- coding:utf-8 -*- import os import time file_list = [] def findFile(path): listFile = os.listdi ...

  6. 转: Apache开启gzip

    Apache开启gzip gzip是什么 HTTP协议上的GZIP编码是一种用来改进WEB应用程序性能的技术.大流量的WEB站点常常使用GZIP压缩技术来让用户感受更快的速度. 这一般是指WWW服务器 ...

  7. 如何使用win7自带的备份还原以及创建系统镜像------傻瓜式教程

    对于经常鼓捣电脑的童鞋来说,装系统是一件极其平常的事情,不过系统装多了之后,我们会感到比较烦躁,因为每一次装系统意味着驱动的重新安装,程序的重新安装,每次这么鼓捣几次,半天时间就花在这上面了,效率是在 ...

  8. python entry points 例子

    pbr的介绍不多,http://ju.outofmemory.cn/entry/156745 $ mkdir entry_test; cd entry_test; git init $ mkdir  ...

  9. codeigniter使用mongodb/redis

    ci2.x版本,使用mongodb,需要安装pecl-php-mongo扩展(github上很多扩展已不可用,找到个可用版本纪录于此),添加到php.ini中 使用如下 public function ...

  10. Extjs4 操作TreeStore 处理proxyAjax 获取的数据

    近期在搞extjs4 TreeStore时有一个需求 就是要处理一下后台传过来的json数据然后再显示,看api也没有找到解决的方法 ,最后看源代码在Ext.data.proxy.Server 看到这 ...