转自:android 打开文件

private void openFile(File f)     {      Intent intent = new Intent();      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);      intent.setAction(android.content.Intent.ACTION_VIEW);            /* 调用getMIMEType()来取得MimeType */      String type = getMIMEType(f);      /* 设置intent的file与MimeType */      intent.setDataAndType(Uri.fromFile(f),type);      startActivity(intent);     }    /* 判断文件MimeType的method */    private String getMIMEType(File f)     {       String type="";      String fName=f.getName();      /* 取得扩展名 */      String end=fName.substring(fName.lastIndexOf(".")      +1,fName.length()).toLowerCase();             /* 依扩展名的类型决定MimeType */      if(end.equals("m4a")||end.equals("mp3")||end.equals("mid")||      end.equals("xmf")||end.equals("ogg")||end.equals("wav"))      {        type = "audio";       }      else if(end.equals("3gp")||end.equals("mp4"))      {        type = "video";      }      else if(end.equals("jpg")||end.equals("gif")||end.equals("png")||      end.equals("jpeg")||end.equals("bmp"))      {        type = "image";      }      else if(end.equals("apk"))       {         /* android.permission.INSTALL_PACKAGES */         type = "application/vnd.android.package-archive";       }       else      {        type="*";      }      /*如果无法直接打开,就跳出软件列表给用户选择 */      if(end.equals("apk"))       {       }       else       {         type += "/*";        }       return type;      } 


更多相关文章

  1. android之ViewFlipper
  2. Android(安卓)文件的选择
  3. Android(安卓)7.0 如何去掉灭屏动画
  4. android用于打开各种文件的intent
  5. Android取得系统信息和分辨率内存信息
  6. Android--取得布局中指定控件的宽高
  7. Android(安卓)使用ADB命令安装、卸载软件
  8. android更新
  9. Qt for Android获取手机热点开关状态

随机推荐

  1. Android应用程序的构成
  2. android版本及版本代号对照
  3. android 开发常用框架、组件 -UI篇
  4. android判断是否禁用了录音权限
  5. Android CountDownTimer实现定时器和倒计
  6. Android(安卓)8.1 中Systemui中的常见修
  7. MaterialDesign系列文章(六)沉浸式状态栏
  8. 免费的Android(安卓)UI库及组件推荐
  9. 定制Android的Home
  10. Android 中文API (61) ―― ViewSwitcher