最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

android调用自带文件选择器获取指定文件,编写解析Uri获取文件绝对路径

业界 admin 20浏览 0评论

标题有点长,不多说

   Intent intent=new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("text/plain");
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        startActivityForResult(intent,REC_REQUESTCODE);

其中“text/plain”是文件的后缀名所对应的MIME类型
当指定两种或两种以上指定文件类型格式是:

//intent.setType("video/*;image/*");//同时选择视频和图片

随手贴上常用的MIME类型

//{后缀名,MIME类型} 
{
  ".3gp", "video/3gpp"}, 
{
  ".apk", "application/vnd.android.package-archive"}, 
{
  ".asf", "video/x-ms-asf"}, 
{
  ".avi", "video/x-msvideo"}, 
{
  ".bin", "application/octet-stream"}, 
{
  ".bmp", "image/bmp"}, 
{
  ".c", "text/plain"}, 
{
  ".class", "application/octet-stream"}, 
{
  ".conf", "text/plain"}, 
{
  ".cpp", "text/plain"}, 
{
  ".doc", "application/msword"}, 
{
  ".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"},
{
  ".xls", "application/vnd.ms-excel"}, 
{
  

标题有点长,不多说

   Intent intent=new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("text/plain");
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        startActivityForResult(intent,REC_REQUESTCODE);

其中“text/plain”是文件的后缀名所对应的MIME类型
当指定两种或两种以上指定文件类型格式是:

//intent.setType("video/*;image/*");//同时选择视频和图片

随手贴上常用的MIME类型

//{后缀名,MIME类型} 
{
  ".3gp", "video/3gpp"}, 
{
  ".apk", "application/vnd.android.package-archive"}, 
{
  ".asf", "video/x-ms-asf"}, 
{
  ".avi", "video/x-msvideo"}, 
{
  ".bin", "application/octet-stream"}, 
{
  ".bmp", "image/bmp"}, 
{
  ".c", "text/plain"}, 
{
  ".class", "application/octet-stream"}, 
{
  ".conf", "text/plain"}, 
{
  ".cpp", "text/plain"}, 
{
  ".doc", "application/msword"}, 
{
  ".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"},
{
  ".xls", "application/vnd.ms-excel"}, 
{
  
发布评论

评论列表 (0)

  1. 暂无评论