开发者

choose a file from device and upload it to page loaded in the webview

开发者 https://www.devze.com 2023-01-31 05:24 出处:网络
In the webview, one page from url is loaded. and in that page, a button for browse file is there in the name \"choose file\".

In the webview, one page from url is loaded. and in that page, a button for browse file is there in the name "choose file". When the user clicks the button, the app should show the gallery to select a file and retrieve it to that page as input. how c开发者_StackOverflow社区an i implement this?


To choose 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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消