和其他App分享文件(4)获取文件信息
2015-01-06 14:57
375 查看
获取文件MIME类型
默认实现返回两列:
DISPLAY_NAME
一个String的文件名,等同于File.getName()的返回值。
SIZE:
文件字节大小,是一个long值等同于File.length()。
例子如下:
... /* * Get the file's content URI from the incoming Intent, then * get the file's MIME type */ Uri returnUri = returnIntent.getData(); String mimeType = getContentResolver().getType(returnUri); ...获取文件名称和大小
FileProvider类有默认实现
, java.lang.String, java.lang.String[], java.lang.String)]query()方法,这个方法返回文件名和大小在相关联的content URI的Cursor中。
默认实现返回两列:
DISPLAY_NAME
一个String的文件名,等同于File.getName()的返回值。
SIZE:
文件字节大小,是一个long值等同于File.length()。
例子如下:
... /* * Get the file's content URI from the incoming Intent, * then query the server app to get the file's display name * and size. */ 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))); ...
相关文章推荐
- ContentProvider(4):怎样获取其他APP分享的数据
- Android官方开发文档Training系列课程中文版:分享文件之获取文件信息
- class-dump获取部分iOS app头文件信息
- android 获取本机其他app的版本信息的示例代码
- 背水一战 Windows 10 (101) - 应用间通信: 通过协议打开指定的 app 并传递数据以及获取返回数据, 将本 app 沙盒内的文件共享给其他 app 使用
- 和其他App分享文件(3)请求一个共享文件
- 通过拖曳获取文件信息的bat代码分享
- 类项目中的配置文件app.config在打包安装后的信息获取的问题
- 类项目中的配置文件app.config在打包安装后的信息获取的问题
- python中怎样获取文件的修改时间及其他系统信息状态-os.stat()
- 【iOS_GitHub】文档/文件查看器(支持本地或者其他app分享过来的word、excel、pdf、rtf等格式文件)
- 对一个apk文件获取相应的版本信息和其他信息
- android 获取本机其他app的版本信息
- Android 获取app应用大小、手机内存信息、删除文件方法、获得文件大小
- Google Android开发者文档系列-创建有内容分享特性的应用之获取文件信息
- 和其他App分享文件(1)设置文件共享
- 类项目中的配置文件app.config在打包安装后的信息获取的问题【转】
- 【笔记】PackageManager获取App基本信息实现Apk导出、分享、卸载
- 类项目中的配置文件app.config在打包安装后的信息获取的问题
- 获取配置文件中configSections的配置信息http://www.linuxmine.com/38234.html