WebView中的文件上傳我一直在努力上傳文件從WebView從過去幾天,沒有任何進(jìn)展。我搜索并實現(xiàn)了所有建議的解決方案,但都沒有效果,比如:建議的解決方案。這里等等。問題:我有一個HTML頁面,上面有下面的代碼來上傳一個文件。它在像Firefox這樣的桌面瀏覽器和內(nèi)置仿真器/AVD瀏覽器中工作得很好,也就是說,當(dāng)我單擊“Browse.”按鈕由元素呈現(xiàn),瀏覽器打開一個對話框,我可以選擇一個文件上傳。但是,在Android3.0模擬器/AVD中,當(dāng)我單擊“選擇文件”時,什么都不會發(fā)生,沒有打開任何文件對話框!<form method="POST" enctype="multipart/form-data">File to upload: <input type="file" name="uploadfile">
<input type="submit" value="Press to Upload..."> to upload the file!</form>有誰能盡快提出一個可行的解決方案嗎?
3 回答

湖上湖
TA貢獻(xiàn)2003條經(jīng)驗 獲得超2個贊
WebView webview;private ValueCallback<Uri> mUploadMessage;private final static int FILECHOOSER_RESULTCODE = 1; @Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == FILECHOOSER_RESULTCODE) { if (null == mUploadMessage) return; Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData(); mUploadMessage.onReceiveValue(result); mUploadMessage = null; }}// Next part class MyWebChromeClient extends WebChromeClient { // The undocumented magic method override // Eclipse will swear at you if you try to put @Override here public void openFileChooser(ValueCallback<Uri> uploadMsg) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); Cv5appActivity.this.startActivityForResult( Intent.createChooser(i, "Image Browser"), FILECHOOSER_RESULTCODE); }}
- 3 回答
- 0 關(guān)注
- 650 瀏覽
添加回答
舉報
0/150
提交
取消