You can use webview on Android, SaleSmartly Android webview Demo example, click to download
<code><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>
</code>
<code class="language-kotlin"> // 启用JavaScript
webView.settings.javaScriptEnabled = true
// 启用 localStorage
webView.settings.domStorageEnabled = true
</code>
For detailed code, please see demo
<code class="language-kotlin"> 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) // 允许多选
register.launch(Intent.createChooser(intent, "Select File"))
return true
}
}
</code>
For detailed code, please see demo
<code class="language-kotlin"> 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) // 允许多选
register.launch(Intent.createChooser(intent, "Select File"))
return true
}
override fun onShowCustomView(view: View, callback: CustomViewCallback) {
// 当视频请求全屏时,显示自定义视图
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() {
// 当退出全屏时,恢复默认视图
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)
}
}
</code>
You need to rewrite the "onShowFileChooser" of webview, please refer to the demo for details.
Use custom view in full screen, hide it after exiting, and display the original view. Please refer to demo for details.
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.
Please check whether the App intercepts or processes the opened link in other ways.
Please check how the App handles link redirects