Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
90 views
in Technique[技术] by (71.8m points)

How do I extract the location of a local file in Android Studio?

I am trying to build a program and I need to allow the user to browse for a specific file in their phone and select a file. I am currently trying to extract the location of the selected file by the user in their phone but I have no idea how I can do that. Can anyone suggest how I can do this, especially what tool I can use in my layout file and how I can extract the location in my main class?

question from:https://stackoverflow.com/questions/66052663/how-do-i-extract-the-location-of-a-local-file-in-android-studio

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First we have to start intent on click of button i.e.

private void openFileManager(int  CODE) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    startActivityForResult(intent, CODE);
}

and we can get path in onActivityResult using

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    String FilePath = data.getDataString();

    //Whatever you want to do .....You can do here

    super.onActivityResult(requestCode, resultCode, data);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...