开发者

View file path in a file manager as Android intent

开发者 https://www.devze.com 2023-02-21 18:03 出处:网络
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.

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 wh开发者_运维知识库en 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.


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消