user3764346
user3764346

Reputation: 129

Android : How do I get the file from the file path

I'am doing File upload task in my application. For that I have used FileChooserActivity Library.

From the docs I have written this code.

Intent intent = new Intent(_context, FileChooserActivity.class);
            Toast.makeText(_context, "inside attachment",
                    Toast.LENGTH_SHORT).show();
            ((Activity) _context).startActivityForResult(intent,
                    FILE_CHOOSER);

public void onActivityResult(int requestCode, int resultCode, Intent data) {
if ((requestCode == FILE_CHOOSER) && (resultCode == RESULT_OK)) {
    String fileSelected = data.getStringExtra(Constants.KEY_FILE_SELECTED);
    Toast.makeText(this, "file selected "+fileSelected, Toast.LENGTH_SHORT).show();
}                    
}

Actually Here I'am getting the file path in fileSelected. But I want to store the selected file in a file object. What I should do for that? Can I convert this path to file? Please help me with some example.

Upvotes: 0

Views: 98

Answers (1)

Happy Cupz Cupz
Happy Cupz Cupz

Reputation: 181

File file = new File(filePath)

Upvotes: 2

Related Questions