Killian
Killian

Reputation: 73

find and select a file in the phone memory

I am creating an application and I would like to select a file in my phone. Do you have ideas to do it?

I would like that when I click on the icon it opens to me the files of the phone (I do not necessarily want the code to be finished, but just creser tracks) enter image description here

enter image description here

Upvotes: 0

Views: 43

Answers (1)

xian
xian

Reputation: 301

Start an intent to get the files with:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent,PICKFILE_RESULT_CODE);

and receive the picked file with:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch(requestCode){
    case PICKFILE_RESULT_CODE:
        if(resultCode==RESULT_OK){
            String FilePath = data.getData().getPath();
            ...
        }
        break;
    }
}

Upvotes: 1

Related Questions