Android Webview Setup Guide
Learn how to configure Android Webview for file uploads and full-screen video playback with this comprehensive guide.
1. Android Webview Implementation Guide
You can use webview on Android. SaleSmartly Android webview Demo example, click to download
1.1 App Manifest Required Permissions
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<br>
1.2 Webview Basic Settings
// Enable JavaScript
webView.settings.javaScriptEnabled = true
// Enable localStorage
webView.settings.domStorageEnabled = true
1.3 Webview File Upload Handling
For detailed code, please see demo:
webView.webChromeClient = object : WebChromeClient() {
override fun onShowFileChooser(
webView: WebView,
filePathCallback: ValueCallback<Array<Uri>>,
fileChooserParams: FileChooserParams
): Boolean {
println("onShowFileChooser")
mUploadMessageAboveL = filePathCallback
val intent = Intent(fileChooserParams.createIntent())
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.type = "*/*"
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true) // Allow multiple selection
register.launch(Intent.createChooser(intent, "Select File"))
return true
}
override fun onShowCustomView(view: View, callback: CustomViewCallback) {
// When video requests full screen, show custom view
if (customView != null) {
callback.onCustomViewHidden()
return
}
customView = view
customViewContainer.visibility = View.VISIBLE
customViewContainer.addView(customView)
customViewCallback = callback
webView.visibility = View.GONE
customViewContainer.bringToFront()
}
override fun onHideCustomView() {
// When exiting full screen, restore default view
customView?.let {
customViewContainer.removeView(it)
customView = null
customViewContainer.visibility = View.GONE
customViewCallback?.onCustomViewHidden()
webView.visibility = View.VISIBLE
}
}
override fun getDefaultVideoPoster(): Bitmap {
return Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888)
}
}
2. Frequently Asked Questions
2.1 No response when clicking to upload pictures or files
You need to rewrite the "onShowFileChooser" of webview, please refer to the demo for details.
2.2 Video playback cannot be full screen or an exception occurs after exiting full screen
Use custom view in full screen, hide it after exiting, and display the original view. Please refer to demo for details.
2.3 Unable to load or display
Please check the network permissions, network status, whether the js imported by the page is correct, and whether the plug-in is enabled. It is recommended to run and test it in the browser first, and then put it into the app for testing after passing.
2.4 No response when clicking the link
Please check whether the App intercepts or processes the opened link in other ways.
2.5 After clicking the link, the browser will jump to the external browser and return to a blank page
Please check how the App handles link redirects.