从设备中选择一个文件并将其上传到webview中加载的页面

4 browser eclipse android android-emulator

在webview中,加载了来自url的一个页面.在该页面中,浏览文件的按钮名称为"选择文件".当用户单击该按钮时,应用程序应显示库以选择文件并将其作为输入检索到该页面.我怎么能实现这个?

Giu*_*sco 6

要选择文件:

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);
Run Code Online (Sandbox Code Playgroud)

然后在你的onActivityResult中:

if(resultCode == RESULT_OK){
   Uri uri = data.getData();
   String filePath = uri.getPath();
   // here goes the code to upload the file
}
Run Code Online (Sandbox Code Playgroud)