Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View file path in a file manager as Android intent

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.

like image 962
R Hill Avatar asked Apr 04 '11 11:04

R Hill


1 Answers

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;
}
like image 118
Bill Mote Avatar answered Sep 21 '22 12:09

Bill Mote