在文件管理器成为Android的意图查看文件路径 [英] View file path in a file manager as Android intent

查看:176
本文介绍了在文件管理器成为Android的意图查看文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只要你知道,我已经选中这两个Android开发文档和 OpenIntents软件,没有找到一个回答。我可能很容易错过了一些东西,但。

Just so you know, I've already checked both the Android developer documentation and OpenIntents, without finding an answer. I might easily have missed something, though.

有用于查看文件管理器的文件路径的意图行动?似乎有一点在当中的Andr​​oid文件管理器应用程序的标准化方法。我不希望有任何不寻常的行为时的意图进行,如果没有文件管理器的安装应该什么都不做,而不是试图操作的文件路径以其它方式。

Is there an intent action for viewing a file path in a file manager? There seems to be little in the way of standardisation among Android file manager apps. I don't want any unusual behaviour when the intent is carried out, and if no file manager is installed it should do nothing, rather than trying to action the file path in some other way.

我的初步研究表明,这可能是目前不可能,但我想我会看到,如果有人知道更好。他们通常做的。

My initial research suggests this probably isn't currently possible, but I thought I'd see if anyone knew better. They usually do.

编辑澄清:我不是在寻找一个文件选择器。我已经有一个文件路径和要打开它在浏览文件管理器/文件浏览器,当且仅当有一个安装在设备上。

Edited to clarify: I'm not looking for a file picker. I already have a file path and want to open it for browsing in a file manager/file browser, if and only if there is one installed on the device.

推荐答案

我有以下...

        Intent intent = new Intent();
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("text/csv");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, getText(R.string.select_file)),1);

然后onActivityResult()

and then onActivityResult()

        currFileURI = data.getData();
        filename_editText.setText(currFileURI.getPath());

更新:解决方法:

UPDATE: SOLUTION:

public static boolean isUriAvailable(Context context, String uri) {
    Intent test = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
    return context.getPackageManager().resolveActivity(test, 0) != null;
}

这篇关于在文件管理器成为Android的意图查看文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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