Retrieving File Information
来源:互联网 发布:知乎web前端必读书籍 编辑:程序博客网 时间:2024/06/07 00:31
可以通过查询提供文件app的FileProvide来得到文件的MIME 和 size.
在得到文件的Uri后,可以调用ContentResolve.getType()来得到文件的类型.FileProvide是根据文件的后缀名来得到文件的类型.
Uri returnUri = returnIntent.getData();
String mimeType = getContentResolver().getType(returnUri);
FileProvide 的query方法可以返回文件的size和name.
FileProvide的返回值是一个Cursor对象,可以通过设定projection=null,selection=null,selectionArgs=null,sortOrder=null。来同时得到文件名和文件size,
Cursor query (Uri uri,
String[] projection,
String selection,
String[] selectionArgs,
String sortOrder)
下面是例子.
Uri returnUri = returnIntent.getData();
Cursor returnCursor =
getContentResolver().query(returnUri, null, null, null, null);
/*
* Get the column indexes of the data in the Cursor,
* move to the first row in the Cursor, get the data,
* and display it.
*/
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
returnCursor.moveToFirst();
TextView nameView = (TextView) findViewById(R.id.filename_text);
TextView sizeView = (TextView) findViewById(R.id.filesize_text);
nameView.setText(returnCursor.getString(nameIndex));
sizeView.setText(Long.toString(returnCursor.getLong(sizeIndex)));
在得到文件的Uri后,可以调用ContentResolve.getType()来得到文件的类型.FileProvide是根据文件的后缀名来得到文件的类型.
Uri returnUri = returnIntent.getData();
String mimeType = getContentResolver().getType(returnUri);
FileProvide 的query方法可以返回文件的size和name.
FileProvide的返回值是一个Cursor对象,可以通过设定projection=null,selection=null,selectionArgs=null,sortOrder=null。来同时得到文件名和文件size,
Cursor query (Uri uri,
String[] projection,
String selection,
String[] selectionArgs,
String sortOrder)
下面是例子.
Uri returnUri = returnIntent.getData();
Cursor returnCursor =
getContentResolver().query(returnUri, null, null, null, null);
/*
* Get the column indexes of the data in the Cursor,
* move to the first row in the Cursor, get the data,
* and display it.
*/
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
returnCursor.moveToFirst();
TextView nameView = (TextView) findViewById(R.id.filename_text);
TextView sizeView = (TextView) findViewById(R.id.filesize_text);
nameView.setText(returnCursor.getString(nameIndex));
sizeView.setText(Long.toString(returnCursor.getLong(sizeIndex)));
0 0
- Retrieving File Information
- Retrieving File Information
- 《Training:Retrieving File Information》
- Information Retrieving
- Retrieving product information in Magento
- Servlet tips --init(), destroy() and retrieving information
- VS error retrieving information from user datastore
- Retrieving CD Information from a remote Freedb database
- 安装VS2005出错“Error retrieving information from user datastore”解决方法
- Incorrect information in file
- .Net与WMI—2(ManagementObject: Retrieving the Management Information)
- iOS and OS X Network Programming Cookbook |Retrieving network address information
- attach extra information to a zip file.
- Finding crash information using the MAP file
- MySQL.1033:,Incorrect,information,in,file:,’.frm’
- Finding crash information using the MAP file
- Adding SVN Information to File Headers Revisited
- Cannot access the ClassView information file
- Maven开发工具的使用方法笔记
- 8大排序之---(2)希尔排序
- 保存数据出现中文乱码-PHP+MySQL
- Zookeeper启动报错
- Linux管道命令
- Retrieving File Information
- 关于SpringOpenSessionInViewFilter的配置及处理方案
- opencv surf特征点匹配拼接源码
- NodeJs--模块获取(为啥使用require)
- 基于webdriver的web UI自动化测试框架(系统架构+测试脚本应用架构)
- IntelliJ idea 2016.2.1 激活
- Java8新特性详解
- 关于oracle的sql语句中 for update 的使用,以及存在的问题
- mybatis连接配置