View file path in a file manager as Android intent

2019-01-23 19:43发布

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.

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.

1条回答
Viruses.
2楼-- · 2019-01-23 20:18

I have the following ...

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

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;
}
查看更多
登录 后发表回答