Reputation: 71
public class MyWebViewChromeClient extends WebChromeClient {
private ValueCallback<Uri> uploadMessage;
private ValueCallback<Uri[]> uploadMessageAboveL;
// For Android >= 5.0
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
File file = new File("storage/emulated/0/Android/data/com.mycompanydomain.proejectname/files/Pictures/JPEG_21652498916216.jpg");
if (file.exists()) {
Log.e("BBBBBBBB","fileexists");
} else {
Log.e("BBBBBBBB","filenotexists");
}
filePathCallback.onReceiveValue(new Uri[]{Uri.parse("storage/emulated/0/Android/data/com.mycompanydomain.proejectname/files/Pictures/JPEG_21652498916216.jpg")});
return true;
}
}
I am trying to handle file upload in webview. I am able to get the file upload request, then I use intent to take a picture and save it to a path successfully. However, it seems that
filePathCallback.onReceiveValue(new Uri[]{Uri.parse("storage/emulated/0/Android/data/com.mycompanydomain.proejectname/files/Pictures/JPEG_21652498916216.jpg")});
not work, because webview doesn't receive the image and nothing happen.
It shows that the file does exist, but the webview just no response and the code above has no effect at all. I cannot figure out what's wrong with the code, can any one help me? Thanks a lot.
Upvotes: 2
Views: 1556
Reputation: 71
I figure out the problem myself finally.
File f=new File("path to file");
Uri u=Uri.fromFile(f);
filePathCallback.onReceiveValue(new Uri[]{u});
The above code works for me.
Upvotes: 5