• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Getting file path from file browser for firebase upload

Currently I have a button which opens a file browser for the user to select a file (currently images) but once they've selected it I'm not sure how I can get the file path and use that to upload it to Firebase storage.

Code:
private void fileChooser(){
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent,"Select a file to upload"),
    REQUEST_CODE);

}

[USER=1021285]@override[/USER]
protected void onActivityResult(int returnedCode, int returnedResult, Intent file){
    super.onActivityResult(returnedCode, returnedResult, file);
    if(returnedCode == REQUEST_CODE && returnedResult == RESULT_OK && file != null && file.getData() != null){
       
    }
}

what would I put inside the if statement to be able to get the filepath and use UploadTask to upload it?
 
Last edited by a moderator:
Specifically, to get the path of the file you chose:

Code:
protected void onActivityResult(int returnedCode, int returnedResult, Intent file){
..
  Uri uri = file.getData();
  String filePath = uri.getPath();
..
}
 
Back
Top Bottom