如何简单地打开目录/文件夹? [英] How to simply open directory/folder?

查看:67
本文介绍了如何简单地打开目录/文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读我需要的内容之前,请勿将其标记为重复.

DONT mark this as duplicate, before reading what I need.

我见过很多类似的话题,但是没有一个找到解决方案.我需要最简单的东西:在我的应用程序中,我具有查看媒体文件"按钮.单击该按钮后,我需要使用内置文件浏览器打开该目录- SD_CARD/my_folder (媒体文件在哪里)(我想单击其中的任何一个,都应在其中打开它们)默认的媒体播放器).

I have seen many similar topics, but in none of them I've found solution. I need the simplest thing: In my application I have button "View Media Files". After clicking that button, i need to be opened (with built-in File Explorer) this directory - SD_CARD/my_folder where are media files (and I want to click any of them and they should be opened in default Media player)..

我在SO上使用了所有建议的答案,就像这样:

I have used all suggested answers on SO , like this:

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri mydir = Uri.parse("/sdcard/Recorder_Videos");
    intent.setDataAndType(mydir, "*/*");
    startActivity(intent);

但是他们所做的全部:单击按钮后,它将打开选择文件"菜单:(单击后仍无法播放媒体文件的地方)

but all they do: after clicking button, it opens "Choose File" menu: (Where I cant still play media files when clicking)

推荐答案

我发现的解决方案(未完成)是我缺少 file://前缀.这是我的解决方案(但是,它在第​​一视图上显示了各种应用程序):

The solution (not complete) I have found, was that I was missing file:// prefix. Here is my solution (however, it shows all kinds of applications on first view):

public void openFolder(String location)
{
    // location = "/sdcard/my_folder";
    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri mydir = Uri.parse("file://"+location);
    intent.setDataAndType(mydir,"application/*");    // or use */*
    startActivity(intent);
}

p.s.奇怪且令人惊讶,但是不存在文件浏览器"的标准定义.有现货的Android系统(除非您安装了第三方文件资源管理器").这就是默认情况下 资源/文件夹" mime-type不起作用的原因.

p.s. Strange and surprising, but there doesnt exist the standard definition of "File Browser" in stock Android systems (unless you install 3rd party "File Explorer").. That's why "resource/folder" mime-type doesnt work by default..

但是,让我们说一个简单的事实.File-Browser是任何OS系统的简单和重要部分.而且,它对Android相当无礼,说这不是他们的工作,而是将责任推给了第三方应用程序.

However, let's say a simple truth. File-Browser is a SIMPLE and ESSENTIAL part of any OS system. And it's quite disrespectful from Android, saying that it's not their job, and throwing the responsiblity to 3rd party apps.

这篇关于如何简单地打开目录/文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆