Select a file from the device and upload it to the page loaded in the web view

In the webview, one page is loaded from the URL. and on this page in the file "select file" there is a button for viewing the file. When the user clicks the button, the application must show a gallery to select a file and upload it to this page as input. how can i implement this?

+4
source share
1 answer

To select a file:

final int CHOOSE_FILE = 1; //... Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT); chooseFile.setType("file/*"); Intent c = Intent.createChooser(chooseFile, "Choose file"); startActivityForResult(c, CHOOSE_FILE); 

Then in your onActivityResult:

 if(resultCode == RESULT_OK){ Uri uri = data.getData(); String filePath = uri.getPath(); // here goes the code to upload the file } 
+6
source

Source: https://habr.com/ru/post/1332211/


All Articles