Min SDK API 15
Hello,
I using a webview that has a button on it that will browse the apps photo gallery.
However, when the button is clicked in the webview, nothing happens.
The url is in the format:
https://www.xxxxxxxxxxx
I have added the following permissions:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
I have a fragment that will load the webview in the onCreateView method (snippet only) with javascript enabled.
if(!message.isEmpty()) {
WebView webView = (WebView)view.findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(message);
}
I have created a simple html page to test:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test Android Popup</title>
</head>
<body>
<label>Test Alert 1:</label>
<button type="button" onClick="alert('Test Alert Box1');">Click Me!</button>
<br>
<label>Test Browse file</label>
<input type="file" name="img">
</body>
</html>
So the url will be loaded into the webview. The webview displays a button that the user will click to browse the photos in their gallery.
The webview looks like this:
None of the buttons work when I click them.
Many thanks for any suggestions,
This code snippet works for < 4.3. However, 4.4 and 5.0 it fails.
webView.setWebChromeClient(new WebChromeClient() {
/* Open File */
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
mImageFilePath = uploadMsg;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent, FILECHOOSER_RESULTCODE);
}
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
mImageFilePath = uploadMsg;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent, FILECHOOSER_RESULTCODE);
}
});
See Question&Answers more detail:
os