Android下可以打开一些文件,带有.doc 等后缀的文件网上一般都有解释,这个写一个使用文件管理器打开指定文件夹的

    private void openAssignFolder(String path){        File file = new File(path);        if(null==file || !file.exists()){            return;        }        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);        intent.addCategory(Intent.CATEGORY_DEFAULT);        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        intent.setDataAndType(Uri.fromFile(file), "file/*");        try {            startActivity(intent);//            startActivity(Intent.createChooser(intent,"选择浏览工具"));        } catch (ActivityNotFoundException e) {            e.printStackTrace();        }    }


打开其他文件的方法,基本上和以上差不多,只是inten的一些属性不同而已,现在列表在下:

Intentintent=newIntent(Intent.ACTION_VIEW);
Uriuri=Uri.fromFile(file);
intent.addCategory(Intent.CATEGORY_DEFAULT);

打开图片文件

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(uri,"image/*");

打开PDF文件

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(uri,"application/pdf");

打开文本文件

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(uri,"text/plain");

打开音频文件

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("oneshot",0);
intent.putExtra("configchange",0);
intent.setDataAndType(uri,"audio/*");

打开视频文件

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("oneshot",0);
intent.putExtra("configchange",0);
intent.setDataAndType(uri,"video/*");

打开CHM文件

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(uri,"application/x-chm");

打开apk文件

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(uri,"application/vnd.android.package-archive");

打开PPT文件

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(uri,"application/vnd.ms-powerpoint");

打开Excel文件

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(uri,"application/vnd.ms-excel");

打开Word文件

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(uri,"application/msword");


如有问题可以发邮件到 friday_holiday@163.com进行讨论




更多相关文章

  1. android 向serverGet和Post请求的两种方式,android向server发送
  2. android使用webview加载flash文件
  3. 修改Android中strings.xml文件
  4. Android获取sd卡上的文件目录-日记
  5. PC上安装android market软件并提取apk文件
  6. 通过终端命令生成并在手机上运行dex文件
  7. Android Studio ——Android 使用Pull方法解析XML文件的方法

随机推荐

  1. Android(安卓)动态横竖屏切换
  2. 安装时提示:INSTALL_FAILED_INSUFFICIENT_
  3. android 源代码下载
  4. Android系统时间
  5. Http 以post方式获取数据
  6. Android(安卓)webview实现上传图片的效果
  7. Android(安卓)半边圆角ImageView
  8. Android:Context上下文菜单、ContextMenu
  9. Android(安卓)联网设置
  10. Android手机开发:ListView的使用