zoukankan      html  css  js  c++  java
  • 安卓 通过intent调用系统文件管理器打开指定路径目录

    安卓 通过intent调用系统文件管理器打开指定路径目录

    转  https://blog.csdn.net/qq_34161388/article/details/78586247


     当我们知道一个文件的路径,如何调用系统文件管理器显示它的位置呢。

    代码:

    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();
            }
        }

     

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri uri = 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");

  • 相关阅读:
    异常之*** buffer overflow detected ***
    多媒体开发之视频回放---dm642 做rtsp 视频回放功能
    理财---炒股之kdj
    多媒体开发之rtp 打包发流--- 从h264中获取分辨率
    多媒体开发之rtsp 实现rtsp over tcp/http/udp---rtsp发送
    tomcat 简介
    tomcat 的安装
    rsync + inotify-tools实现文件的实时同步
    python 生成器
    ansible 常用模块
  • 原文地址:https://www.cnblogs.com/it-tsz/p/11179283.html
Copyright © 2011-2022 走看看