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. 入坑 React Native 之简单分析项目结构
  2. Android(安卓)SDK下载和更新失败的解决方法!!!
  3. Android(安卓)ROM研究---Android(安卓)build system增加模块
  4. 用Android代码实现打开USB调试
  5. JetPack 之 DataBinding 的使用
  6. S3C6410(M8用的) 移植Android(安卓)内核
  7. Android—— ubuntu下【CTS】测试TV真机
  8. android 如何保护我们的app(二)(干货)
  9. NPM 和webpack 的基础使用

随机推荐

  1. Android(安卓)HttpClient
  2. Android(安卓)多线程更新控件
  3. Android之自定义Adapter的ListView
  4. android 弹出视频
  5. Android中Broadcast的Intent大全
  6. Download Android(安卓)1.5 SDK, Release
  7. android典型代码系列(三十)------DES加密
  8. [android]上下文菜单
  9. android studio 0.80多渠道打包
  10. Android网络状态监听